从SQL数据库中动态获取变量并将其显示在网页上的表单,用户从该表单中选择任何选项后,它应存储在一些变量中。
<form id="form1" name="quest" method="POST" action="" style="margin-left:60px;">
$connect = mysql_connect("localhost","root","")
or die(mysql_error());
$sel=mysql_select_db("demo");
$query = mysql_query("SELECT * FROM `microsoftq` ORDER BY RAND() LIMIT 1 ");
$rows1 = mysql_fetch_array($query);
$q1 = $rows1['QNo'];
$qus1 = $rows1['Question'];
$a1 = $rows1['Opt1'];
$b1 = $rows1['Opt2'];
$c1 = $rows1['Opt3'];
$d1 = $rows1['Opt4'];
$ans1 = $rows1['Ans'];
echo " <b>Question:-<br></b>$qus1 <br><br>";
echo " <input type=radio name = 'answer$q1' ></input>$a1    <br>";
echo " <input type=radio name = 'answer$q1' ></input>$b1    <br>";
echo " <input type=radio name = 'answer$q1' ></input>$c1     <br>";
echo " <input type=radio name = 'answer$q1' ></input>$d1 <br><br> ";
<input type="submit" id="submit_id" name="SUBMIT" value="SUBMIT">
</form>
我正在尝试将变量存储在这种类型中,工作但是从数据库中随机选择值,其中一些也缺失了,...
<?php
if (isset($_POST['SUBMIT']))
{
$connect = mysql_connect("localhost","root","")
or die(mysql_error());
$sel=mysql_select_db("demo");
$opt1=$_POST["answer$q1"]; // problem is here
$id1=array("$q1","$opt1");
if($ans1==$opt1)
{
$val1="ct";
}
else
{
$val1="wg";
}
mysql_query("insert into stu1 values('$id1[0]','$id1[1]','$val1')")
or die(mysql_error());
?>
所以有人会帮助我解决这个问题,...