Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7053957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:34:04+00:00 2026-05-28T03:34:04+00:00

I have a PHP script that allows users to enter grades by selecting a

  • 0

I have a PHP script that allows users to enter grades by selecting a radio button that corresponds to the students grade. It allows them to view the selected grades before they can be finally submitted. I also want the page to have the ability to go back to the selection page and remember the radio buttons that were selected so that the user doesn’t have to set all of them again when going back. Here is what I have coded so far, it takes the user back to selection page but doesn’t restore the radio button selection.

<?php

session_start();

$script_name = $_SERVER["PHP_SELF"];

if(!isset($_SESSION["course"]) || !isset($_SESSION["course"])) {
    $_SESSION["course"] = $_POST["coursename"];
    $_SESSION["section"] = $_POST["section"];
}

if(($_SESSION["authenticated"] == true || isset($_POST["back"])) && !isset($_POST["continue"])) {

    $course = $_SESSION["course"];
    $section = $_SESSION["section"];
    $file_name = $course.$section.".txt";
    $_SESSION["filename"] = $file_name;

    // Open file containing student names.
    $fp = fopen($_SESSION["filename"], "r") or die("Could not open file");
    $students = array();
    $i = 0;

    echo "<h2>Grades Submission Form</h2>";
    echo "<h2>Course: $course, Section: $section</h2>";
    echo "<form action=\"$script_name\" method='post'>";
    echo "<table border='1'>";
    while (!feof($fp)) {
        $line = trim(fgets($fp));
        $students[$i++] = $line;

        echo "<tr><td>$line</td>";
        echo "<td><input type='radio' name=\"$line\" value='A'/>A</td>";
        echo "<td><input type='radio' name=\"$line\" value='B'/>B</td>";
        echo "<td><input type='radio' name=\"$line\" value='C'/>C</td>";
        echo "<td><input type='radio' name=\"$line\" value='D'/>D</td>";
        echo "<td><input type='radio' name=\"$line\" value='F'/>F</td>";
        echo "</tr>";
    }
    echo "</table><br>";
    echo "<input type='submit' name='continue'/>";
    echo "</form>";

} elseif($_SESSION["authenticated"] == true && isset($_POST["continue"]) && !isset($_POST["back"])) {

    unset($_POST["continue"]);
    $keys = array_keys($_POST);
    $values = array_values($_POST);

    echo "<h2>Grades to Submit</h2>";
    echo "<table border='1'>";
    echo "<tr><th>Name</th><th>Grade</th></tr>";
    for($i = 0; $i < count($keys); $i++) {
        echo "<tr><td>{$keys[$i]}</td><td>{$values[$i]}</td></tr>";
    }
    echo "</table><br>";

    echo "<form action='confirmation.php' method='post'>";
    echo "<input type='submit' value='Submit Grades'/>";
    echo "</form>";

    echo "<form action=\"$script_name\" method='post'>";
    echo "<input type='submit' value='Back'/>";
    echo "</form>";

} else {
    header("Location: main.php");
}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:34:04+00:00Added an answer on May 28, 2026 at 3:34 am

    You could serialize() an array containing the radio button states and store it in your session. When you go back, all you have to do is unserialize it and set the data again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php script that allows users to upload multiple files to server
I have php script that creates a temporary watermark image for users that are
I have a script that allows users to 'save as' a pdf, this is
On the front-end, I have a PHP webapp that allows users to create a
I have a script that allows only authorised users to upload files to a
I have the following php script that allows me perform some calls to other
I have a PHP script that pushes the headers to allow a file to
I have a PHP script that runs as a CGI program and the HTTP
I have a PHP script that needs to determine if it's been executed via
I have a PHP script that initialises an image gallery. It loops through all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.