This feels like a common problem, but it's a difficult one to Google!
As explained in the comment in the code, inserting the value was previously not a problem but stopped working when I added the additional INSERT
queries below it.
$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());
}
}
}
mysql_real_escape_string
or even better, PDO.print_r($variable)
to check all your variables before adding it in mysql query, and if it is array than get the required value with$variable['key']
. And BTW Please stop writing new code with the ancient mysql_* functions. They are no longer maintained.