我想從選中的單選按鈕獲取一個值並將其插入到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");
}
回聲$ _ POST [ '導師']返回此 'mentormentormentormentor'
如果可以的話,你應該[停止使用'mysql_ *'函數](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。他們不再被維護,並[正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。瞭解[準備](http://en.wikipedia.org/wiki/Prepared_statement)[聲明](http://php.net/manual/en/pdo.prepared-statements.php),並考慮使用PDO ,[這真的不難](http://jayblanchard.net/demystifying_php_pdo.html)。 –
[你的腳本存在SQL注入攻擊風險](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) –
什麼是echo $ _POST [ '導師'];'返回? – Lal