php - Inserting radio button input in the database -
i'm creating quiz-like structure. i'm trying answer of each question , insert database type of question answered. i'm having trouble putting these data in variables , i'm getting: notice: undefined index: question-0-answer
in commented part of code. help..
$options = ''; $filter=mysql_query("select afnumber employees status='employed '"); while($row = mysql_fetch_array($filter)) { $options .="<option >" . $row['afnumber'] . "</option>"; } $menu="<form id='filter' name='filter' method='post' action=''> afnumber : <select name='selectaf' id='filter' style='color:grey;'>" . $options . "</select> evaluation test type : <select name='type' id='type' style='color:grey;'><option selected='selected'></option><option value='loyalty'>loyalty</option><option value='performance'>performance</option></select> <input type='submit' name='submit1' value='submit' style='width:80px; height:30px; text-align:center; padding:0px;'> </form> <br> "; echo $menu; if(isset($_post['submit1'])) { $type = $_post['type']; $mysqli = new mysqli("localhost", "root", "js", "jr"); /* check connection */ if ($mysqli->connect_errno) { printf("connect failed: %s\n", $mysqli->connect_error); exit(); } if ( $result = $mysqli->query( "select questiontext questioninfo type='$type'" ) ) { $html=array(); $html[]=" <form action='' method='post' id='quiz'> <ol>"; $counter=1; while( $row = $result->fetch_array() ) { $question=$row['questiontext']; $answera=1; $answerb=2; $answerc=3; $answerd=4; $answere=5; $html[]=" <br/> <h3>question {$counter}: {$question}</h3> <li> <br/> <input type='radio' name='question-{$counter}-answers' id='question-{$counter}-answersa' value='a' /> <label for='question-{$counter}-answers-a'> {$answera} </label> <br/> <input type='radio' name='question-{$counter}-answers' id='question-{$counter}-answersb' value='b' /> <label for='question-{$counter}-answers-b'> {$answerb} </label> <br/> <input type='radio' name='question-{$counter}-answers' id='question-{$counter}-answersc' value='c' /> <label for='question-{$counter}-answers-c'> {$answerc} </label> <br/> <input type='radio' name='question-{$counter}-answers' id='question-{$counter}-answersd' value='d' /> <label for='question-{$counter}-answers-d'> {$answerd} </label> <br/> <input type='radio' name='question-{$counter}-answers' id='question-{$counter}-answerse' value='e' /> <label for='question-{$counter}-answers-e'> {$answere} </label> </li>"; $counter++; } $html[]=" </ol> <input type='submit' name='submit' value='submit' style='width:80px; height:30px; text-align:center; padding:0px;'> <input type='hidden' name='type' value='{$type}' /> </form>"; echo implode( php_eol, $html ); $result->close(); } } /* if( isset( $_post['submit'] ) ){ $numquestions=10; for( $counter=0; $counter < $numquestions; $counter++ ){ $answer=$_post['question-'.$counter.'-answers']; $sql="insert `question` (`type`,`value`) values ('".$type."','".$answer."')"; $db->query( $sql ); } } */
the $counter
outputting radiobuttons initialized value 1
when reading values of radiobuttons @ end of script, starting $counter = 0;
.
please change
for( $counter=0; $counter < $numquestions; $counter++ ){
to
for( $counter=1; $counter <= $numquestions; $counter++ ){
Comments
Post a Comment