我正在尋找將單個選擇插入到多個用戶的字段中。當進行選擇並輸入提交時,我有以下代碼。我沒有收到任何錯誤,我在下一頁發佈了5次郵件,這是多少用戶不是它的weekpicks表。但是沒有任何內容插入到數據庫中。如何插入同一分區中的多個字段
<?
// This code is to use to place info into the MySQL
$sTeam1 = $_POST['sTeam1'];
// (WHERE username FROM authorize WHERE username not in (SELECT username FROM weekpicks WHERE whatweek='$totalnoOfWeek')" .
//$nMemberID = (integer) Query
$sql_events = mysql_query("SELECT username FROM authorize WHERE username not in (SELECT username FROM weekpicks WHERE whatweek='$totalnoOfWeek')") or die(mysql_error());
while ($row = mysql_fetch_array($sql_events)) {
$username = $row["username"];
("INSERT INTO weekpicks SET " . "username = '" . ($username) . "'," . "date_create = NOW(), " . "whatweek = '" . ($totalnoOfWeek) . "'," . "team = '" . addslashes($sTeam1) . "'" . 'INSERT');
echo "<HTML>
<BODY>
<h2>Your pick of " . ($sTeam1) . ", for week " . ($totalnoOfWeek) . ", has been added.</h2>
<P align=left><a href=\"nopickpolicy.php\">Return to main page</a></p>
</BODY>
</HTML>";
}
?>
請注意,[** mysql_ *功能已被棄用**](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in- PHP)並刪除較新版本的PHP。另外值得一提的是[如何防止PHP中的SQL注入?](http://stackoverflow.com/q/60174/4577762)。 – FirstOne