[英]Get a selected value from radio button and insert it to MySQL
我想从选中的单选按钮中获取一个值,并将其插入MySQL。
我已经使用过isset(),但是当我检查结果时,无法获得所选的单选按钮。
有人能帮我吗?
<form method="post" class="input" action="doRegisCourse.php">
<table>
<?php
while($row=mysql_fetch_array($query)){
?>
<tr>
<td><input type="radio" value="mentor" name="mentor"/></td>
<td><?php echo $row['mentorName']?></td>
<td><?php echo $row['course']?></td>
<td><?php echo $row['nim']?></td>
<td><?php echo $row['email']?></td>
</tr>
<?php } ?>
</table>
<input type="submit" value="Next" name="submit">
</form>
doRegisCourse.php
<?php
include "connect.php";
$name = $_POST['fullname'];
$name2 = $_POST['fullname2'];
$name3 = $_POST['fullname3'];
$course = $_POST['course'];
$mentor = mysql_query("SELECT * from msmentor");
$i = 1;
while ($arr = mysql_fetch_array($mentor)) {
if (isset($_POST['mentor'])) {
$query = "INSERT INTO membercourse(memberGroup,courseName,mentorName)
VALUES ('".$name."','".$course."','".$arr['mentorName']."'),('".$name2."','".$course."','".$arr['mentorName']."'),
('".$name3."','".$course."','".$arr['mentorName']."')";
echo $_POST['mentor'];
}
$i++;
}
if (mysql_query($query)) {
header("location:indexLogin.php");
}
echo $ _POST ['mentor']返回此'mentormentormentormentor'
当前的书写方式( <input type="radio" value="mentor" name="mentor"/>
),所有单选按钮将具有相同的值: "mentor"
。 您需要将值设置为等于指导者的姓名,如下所示:
<input type="radio" value="<?php echo $row['mentorName']?>" name="mentor"/>
然后,在doRegisCourse.php
,您实际上并没有从$ _POST拉出选定的指导者。 您正在检查是否设置了$_POST['mentor']
,但是您要INSERT
membercourse
是从另一个mysql查询中获取的,而不是从发布的值中获取的。
那可能就是您的想法,但是让人们选择导师的价值然后又不真正使用它似乎很奇怪。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.