gpt4 book ai didi

php - 从 while 循环获取单选按钮值

转载 作者:行者123 更新时间:2023-11-29 22:15:50 24 4
gpt4 key购买 nike

如何从 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>

这是我的“verify.php”

<?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++;
}

}
?>

那么,用户提交表单后如何获取单选按钮的值?谢谢。

最佳答案

您需要使用这个:

$_POST['radio'];

将“radio”替换为您的 radio 输入名称。

关于php - 从 while 循环获取单选按钮值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31216220/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com