这感觉像是一个常见问题,但对 Google 来说却是一个难题!
正如代码中的注释中所解释的,插入该值以前不是问题,但是当我在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());
}
}
}