【发布时间】:2015-11-10 05:50:01
【问题描述】:
我想从选中的单选按钮中获取一个值并将其插入 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'] 返回这个 '辅导老师'
【问题讨论】:
-
如果可以的话,你应该stop using
mysql_*functions。它们不再被维护并且是officially deprecated。改为了解 prepared statements,并考虑使用 PDO,it's really not hard。 -
echo $_POST['mentor'];返回什么? -
尝试检查 POST 数据。在 PHP 文件的开头添加
var_dump($_POST)并查看 POST 数组是否包含mentor。