hi , thanks in advance guys for your help I am preparing a quiz which has question and multiple options
i am currently working to fetch data from database as radio buttons for which i am successful but on inserting that into a database gives me a blank value and on top of it the radio button is not sticky for each mcqs
code for fetching the data
<?php $dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$db='tutorial';
$conn = mysqli_connect($dbhost, $dbuser, $dbpass,$db);
if(isset($_POST['value'])){ $value = $_POST['value']; }
if(! $conn )
{
die('Could not connect: ' . error);
}
$sql = 'SELECT q1,option1,option2,option3 FROM questions ';
$result = mysqli_query( $conn, $sql);
if(! $result )
{
die('Could not get data: ' );
}
while($row = mysqli_fetch_array($result))
{
echo "{$row['q1']}" .'</br></br>'.
" A <input type='radio' name='RadioGroup1' value='ans' id ='ans' 'checked=checked'>" . $row['option1'] . '<br> ' .
" B <input type='radio' name='RadioGroup1' value='ans'>" . $row['option2'] . '<br> '.
" C <input type='radio' name='RadioGroup1' value='option3']}'>" . $row['option3'] . '<br> '.'<br>';
//"--------------------------------<br>");
}
echo "<form name=\"insert\" action=\"dbinsert.php\" method=\"post\">";
echo "<input type=\"submit\" value=\"submit\">";
echo "</form>";
mysqli_close($conn)?>
the insertion part code is here
if(isset($_POST['value'])){ $value = $_POST['ans'];}
if(! $link )
{
die('Could not link: ' . error);
}
$id='null';
$ans = mysqli_real_escape_string($link, $_POST['ans']);
//$first_name = mysqli_real_escape_string($link, $_POST['first_name']);
$sql = "INSERT into base (ans)VALUES ('$ans')";
if(mysqli_query($link, $sql)){
echo '<a href="quiz2.html">BEGIN TEST</a>';
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
mysqli_close($link);