我正在爲我的公司進行在線能力測試,它將從數據庫中挑選20個隨機問題並將其顯示在網頁上以供回答。將無線電輸入按鈕的值存儲到SQL數據庫
但我有在SQL數據庫存儲回答值問題,請任何一個能幫助我解決這個問題,
<?php
$connect = mysql_connect("localhost","root","")
or die(mysql_error());
$sel=mysql_select_db("aptitude");
$query = mysql_query("SELECT * FROM `questions` ORDER BY RAND() LIMIT 20 ");
while($rows = mysql_fetch_array($query)){
$q = $rows['QNo'];
$qus = $rows['Question'];
$a = $rows['Opt1'];
$b = $rows['Opt2'];
$c = $rows['Opt3'];
$d = $rows['Opt4'];
$ans = $rows['Ans'];
echo "<b>Question:-<br></b>$qus <br>";
echo " <input type=radio name = 'answer[$q]' value = '$a'></input>$a    ";
echo " <input type=radio name = 'answer[$q]' value = '$b'></input>$b    ";
echo " <input type=radio name = 'answer[$q]' value = '$c'></input>$c     ";
echo " <input type=radio name = 'answer[$q]' value = '$d'></input>$d <br><br> ";
}
?>
,但我的用戶點擊後試圖存儲值上提交按鈕: -
if (isset($_POST['SUBMIT']))
{
$username=$_GET['username'];
$opt1=$_POST["answer1"];
$opt2=$_POST["answer2"];
mysql_query("insert into $username values('Q1','$answer1')")
or die(mysql_error());
mysql_query("insert into $username values('Q2','$answer2')")
or die(mysql_error());
}
你在$ _POST什麼陣列[「答案「],提交表單後? – Khushboo 2014-09-22 10:43:41
請參閱更新的問題,... – 2014-09-22 10:53:06