gpt4 book ai didi

php - 如果取消选中一个单选按钮,会显示错误吗?

转载 作者:行者123 更新时间:2023-11-29 13:59:18 24 4
gpt4 key购买 nike

如果我以 mysql_* 格式询问,我很抱歉,因为这就是我现在正在使用的格式。还是希望大家能够帮助我。

所以我的问题是,一旦提交表单,其中一行单选按钮未被选中,我就会尝试显示错误。但是,根据我的代码,它仅出现在特定行上,而不是作为顶部的单个消息,因为我认为我已将其包含在 While 循环中。你们能建议一种方法吗?无论是 javascript 还是函数,我都可以接受。我只是不知道该怎么做:P。

这是我的代码:

while($fetch=mysql_fetch_array($query)){

//DISPLAY ALL ANSWERS
if(isset($_POST['voted'])){
if(in_array($_POST['score('.$fetch['questionID'].')'], $radioValue)){
echo "<tr>Question no. ",$fetch['questionID'],": ",
$_POST['score('.$fetch['questionID'].')'],"<br></tr>";
}
else{
echo "<center><font color=red>All fields are required</font><br><br>
<input type='button' name='return' value='Return' onclick='history.go(-1)'><br>";
exit();
}
}

//DISPLAYS QUESTIONS WITH QUESTION NUMBER
echo "<tr align=left><th><font face='Courier New,arial' size=2px>".$fetch["questionID"].". ".$fetch["question"]."<br>
<td><font face='Courier New,arial' size=2px>";


//DISPLAYS RADIO BUTTONS FROM 1 to 5
for($i = 1; $i < 6; $i++){
echo "<input type=radio name='score(".$fetch["questionID"].")' value=",$i," >"; echo $i;
}

}

最佳答案

我会在 while 循环中放置一个变量来检查错误。类似于以下内容:

$validationFailed = false;
while($fetch=mysql_fetch_array($query)){

//DISPLAY ALL ANSWERS
if(isset($_POST['voted'])){
if(in_array($_POST['score('.$fetch['questionID'].')'], $radioValue)){
echo "<tr>Question no. ",$fetch['questionID'],": ",
$_POST['score('.$fetch['questionID'].')'],"<br></tr>";
}
else{
$validationFailed = true;
exit();
}
}

//following should be outside the while loop.
if($validationFailed) {
echo "<center><font color=red>All fields are required</font><br><br>
<input type='button' name='return' value='Return' onclick='history.go(-1)'><br>";
}

关于php - 如果取消选中一个单选按钮,会显示错误吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15336141/

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