Forum Moderators: coopster

Message Too Old, No Replies

Php -i need help about radio button

         

spineless

7:38 am on May 16, 2008 (gmt 0)

10+ Year Member



i create some radio buttons by using for loop... form call values from database and create radio buttons with numbers of questions.
i want to post the values of radio buttons. Actually i want to count the numbers of corrects values which are selected...
please help me.. my english is not goog enough . i hope u understand my problem...

<?php
include('database_access_param.php');
if(($qnumber=="")¦¦($qnumber==0))
{
$qnumber=1;

}
else
{
$qnumber=$qnumber+1;
}

$acount=0;
$answers = array();
$question="";
$answerblock=array();
$rightanswer=array();

$db_link=mysql_connect($hostname, $dbuser, $dbpassword) or die("Unable to connect to the server!");

mysql_select_db($dbname) or die("Unable to connect to the database.");

$sql = "select * from questions where qnumber=".$qnumber ;


print('<html>');
print('<head><title>');
print('Quiz 1</title>');
print('<link rel="stylesheet" href="report.css">');

print("</head>");
print('<body>');
print('<form name="form1" method="post" action="go2.php">');
print('<table class="report" align=left width=100%>');
print('<tr><th align=left colspan=2>Quiz</th></tr>');
print('<tr><td>&nbsp</td></tr>');

$result=mysql_query($sql);

//;

if(mysql_numrows($result))
{
$row = mysql_fetch_row($result);
{

//print('<tr><td>'.$result2.'</td></tr>');

//$i=0;
//for($i=0; $i<20 ; $i++)
//{

$qid=1;

$sqln = "select * from questions where qid=".$qid ;
$z=0;
for($z=0;$z<100;$z++){


$sqln = "select * from questions where qid=".$qid ;
$qid=$qid+1;


$result2=mysql_query($sqln);

//;

if(mysql_numrows($result2))
{
$row = mysql_fetch_row($result2);
{

//$qid=$row[0];
$question=$row[1];
$answers[0]=$row[2];
$answers[1]=$row[3];
$answers[2]=$row[4];
$answers[3]=$row[5];
$answers[4]=$row[5];

$qnumber=$row[6];

$rightanswer=$row[2];

srand((float) microtime() * 10000000);

$rand_keys = array_rand($answers, 5);

$answer0=$answers[$rand_keys[0]] ;
$answer1=$answers[$rand_keys[1]] ;
$answer2=$answers[$rand_keys[2]] ;
$answer3=$answers[$rand_keys[3]] ;
$answer4=$answers[$rand_keys[4]] ;

print('<tr><td>'.$qnumber.')<input type="radio" name="answer['.$z.']" value="'.$answer0.'"><input type="radio" name="answer['.$z.']" value="'.$answer1 .'"><input type="radio" name="answer['.$z.']" value="'.$answer2.'"><input type="radio" name="answer['.$z.']" value="'.$answer3 .'"><input type="radio" name="answer['.$z.']" value="'.$answer4 .'"></td></tr>');

$qcount=$qcount+1;

if($rightanswer == $answer){
$acount=$acount + 1;
}

//else

}
//}
//end of for....
}
}
//print('<tr><td>&nbsp<input type=hidden name=rightanswer value="'.$rightanswer.'"><input type= hidden name=qnumber value="'.$qnumber.'"></tr>');

}
print('<tr><td colspan=2><input type=submit name=submit value="Submit" >&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type=reset name=reset value="Clear" ></td></tr></table>');

print('<p>You cannot go back and resubmit an answer.&nbspSystem counts every submit and it affects your score</p>');

}
else
{

//print('<input type =hidden name=score value="'.$score.'">');
//print('<tr><td colspan=2align=center><input type=submit name=submit value="Grade" ></td></tr></table>');
//print('</form>');

}

print('</body>');
print('</html>');

?>

coopster

4:15 pm on May 20, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, spineless.

One way to view what is being submitted by the form is to dump the superglobal of the action of the form. For example, you are using:

<form name="form1" method="post" action="go2.php">

Since your method is "post" you can dump the PHP $_POST superglobal array at the top of the script named in the action attribute, or "go2.php" in this case.
<?php 
print '<pre>';
print_r($_POST);
print '</pre>';
exit;
?>

Now you can see the structure of the $_POST array. Some helpful links from the PHP manual:

Variables from outside PHP [php.net]
PHP and HTML [php.net]