My PHP/HTML Radio Button Form in a loop is not working. Why?


   $_SESSION['ValueSelected'] = $_POST['subject'];

   $opt = array();

    for($row=1; $row<=65; $row++)
           if($Set_Details[0][$row - 1] == $userinID)    
          echo '<input type="radio" name="subject" value="$opt[$num]"> ' . $Set_Details[1][$row-1] . ' - '. $Set_Details[3][$row-1] . '<br>';

Let me explain my code. $Set_Details is a double dimensional array and it is working without any problems. Based on the number of subjects a teacher has, that many radio buttons will be generated. Each of them has a common name but different values. Each of the subjects displayed can be selected through a radio button. Now, I want to send the selected option to another page. How should I go about doing this? Without:

$_SESSION['ValueSelected'] = $_POST['subject'];

The program runs normally. Only when I put this line, errors are generated. It says:

Notice: Undefined index: subject in C:\xampp\htdocs\GradingPortal\FacultyIndex.php on line 98



If you run the query with a GET request (i.e. just load the page) you will get an error because the$_POST variable would not be sent. Doing the following will remove the debug message but may not solve logical issues you may have

$_SESSION['ValueSelected'] = (isset($_POST['subject'])) ? $_POST['subject'] : null;



try this

$_SESSION['ValueSelected'] = isset($_POST['subject']);

or try this

$_SESSION['ValueSelected'] = @$_POST['subject'];

People are also looking for solutions to the problem: php embedded in html "->" interpreted as tag


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.