homepage Welcome to WebmasterWorld Guest from 54.211.100.183
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
How to get radio button values in php array variable
radio button , php array
Rajasekar29



 
Msg#: 4479364 posted 8:13 am on Jul 27, 2012 (gmt 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.

<?php
require('connect.php');
$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))
{
$id=$row['0'];
$question=$row['1'];
$opta=$row['2'];
$optb=$row['3'];
$optc=$row['4'];
$optd=$row['5'];
$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>";
}

 

MaxPowers



 
Msg#: 4479364 posted 8:26 pm on Jul 31, 2012 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved