這感覺就像一個共同的問題,但它是一個很難谷歌!
正如代碼註釋中所述,插入值以前不是問題,但在我在其下面添加其他INSERT
查詢時停止工作。
$user = $_POST['name'];
$night = $_POST['club'];
$query = mysql_query("SELECT day FROM nights WHERE name = '$night'");
$email = $_POST['email'];
while ($row = mysql_fetch_assoc($query)) {
$date = getFullDateString($row['day']);
$date2 = getDateString($row['day']);
}
// this one previously worked but now enters into the database with $user as "Array"
mysql_query("INSERT INTO guestlists (guest, night, date) VALUES('$user', '$night', '$date') ") or die(mysql_error());
$guest1 = $_POST['name1'];
$guest2 = $_POST['name2'];
// these were added later and work fine but seem to have had an effect on the query above
mysql_query("INSERT INTO guestlists (guest, night, date) VALUES('$guest1', '$night', '$date') ") or die(mysql_error());
mysql_query("INSERT INTO guestlists (guest, night, date) VALUES('$guest2', '$night', '$date') ") or die(mysql_error());
foreach ($_POST as $key){
if (is_array($key)){
foreach ($key as $key2 => $value){
mysql_query("INSERT INTO guestlists (guest, night, date) VALUES('$value', '$night', '$date') ") or die(mysql_error());
}
}
}
我很困惑,這4個插入中的哪一個正在做什麼? – 2012-06-13 09:56:17
$ value比數組可用is_array檢查。而你的代碼要求所有的mysql注入。 –
哦,不,SQL注入!你的代碼很容易受到攻擊。請使用'mysql_real_escape_string'或更好的PDO。 – kapa