Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

How to get radio button values in php array variable

radio button , php array

8:13 am on Jul 27, 2012 (gmt 0)

New User

joined:July 27, 2012
posts: 1
votes: 0

This is my code to display list of questions and 4 options( using option box). user has to select the correct option . Is it possible to store the user selected options in array variable. There may be 10 to 20 questions array variable should contain only option values.

$display=mysql_query("SELECT * FROM Java_Test_1 ORDER BY id ASC");
echo "<form method=post action=$PHP_SELF>";
echo "<table border=0>";
while ($row = mysql_fetch_array($display))
$answer = $row["woptcode"];
echo "<tr><td colspan=3><br><b>$question</b></td></tr>";
echo "<tr><td>$opta<input type=radio name=$id value='a'></input></td><td>$optb <input type=radio name=$id value='b'></input></td><td>$optc <input type=radio name=$id value='c'></input></td><td>$optd <input type=radio name=$id value='d'></input></td></tr>";
echo "</table>";
echo "<input type='submit' value='start' name='doo'>";
echo "</form>";
8:26 pm on July 31, 2012 (gmt 0)

New User

joined:July 31, 2012
votes: 0

This would need to happen after a user selects an option and submits the form. PHP is not available after the page has been sent to the user. Once they click submit, you can catch their response and place it in an array of some sort.

Look into PHP Sessions and serialized arrays to help your application remember a particular users answers across several pages of input.