如何从while循环中获取单选按钮的值?
这是我从数据库中检索数据的代码:
<form action="verify.php" method="POST">
<?php
$con=mysqli_connect("localhost","root","","database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "SELECT * FROM question WHERE ID_Q LIKE 'A%'" ;
$result = mysqli_query($con,$sql);
$count=mysqli_num_rows($result);
$kira=1;
while($x = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>$kira.</td>";
echo "<th>" . $x['Question']."</th>";
echo "</tr>";
echo "<tr>";
echo "<td></td>";
echo "<td>";
$sql2 = "SELECT * FROM answer WHERE ID_question ='$x[ID_Q]'" ;
$result2 = mysqli_query($con,$sql2);
$count2=mysqli_num_rows($result2);
while($y = mysqli_fetch_array($result2)){
echo "<input type='radio' name=answer[".$x['ID_Q']."] value=val[".$y['weight_pre']."]>".$y['answer'];
echo "<br>";
}
echo "</td>";
//echo "<td>".$x['pic']."</td>";
echo "</tr>";
$kira++;
}
?>
<button type="submit"> Kira </button>
</form>
这是我的&#34; verify.php&#34;
<?php
session_start();
$a=$_GET['name'];
$b=$_GET['value'];
$c=$_SESSION['ID_user'];
if(!isset ($_SESSION['ID_user'])){
echo "You have to log in to be able to view this page.";
echo "<meta http-equiv='Refresh' content='1;index.php'>";
die();
}
else {
// Create connection
$con=mysqli_connect("localhost","root","","database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$s=0;
while ($s<=20){
$sql = "INSERT INTO answer_user(ID_user, ID_question, answer,
weight) "."VALUES ('$c','$a','','$b')";
$result = mysqli_query($con,$sql);
$s++;
}
}
?>
那么,一旦用户提交表单,我怎样才能获得单选按钮的价值?感谢。
答案 0 :(得分:0)
你需要使用它:
$_POST['radio'];
将“无线电”替换为您的无线电输入名称。