我试图将我的会话当前持有的值插入到我的mysql表中。
$insert_sql = 'INSERT INTO booked_rooms (date_start, date_end, adults, children, fk_room_id, title, first_name, last_name, address, city, state_province, zip_postal, telephone, email)
VALUES ('.$_SESSION['date_start'].$_SESSION['date_end'].$_SESSION['adults'].$_SESSION['children'].$_SESSION['room_id'];', $title , $first_name , $last_name , $address , $city , $state , $zip , $telephone , $email)';
$insert = mysqli_query($con, $insert_sql) or die ($mysqli_error());
它应该可以工作,但我不确定如何在此上下文中使用$ _session变量
答案 0 :(得分:0)
您的查询中存在一些错误。试试这个
$insert_sql = 'INSERT INTO booked_rooms (date_start, date_end, adults, children, fk_room_id, title, first_name, last_name, address, city, state_province, zip_postal, telephone, email)
VALUES ("'.$_SESSION['date_start'].'","'.$_SESSION['date_end'].'","'.$_SESSION['adults'].'","'.$_SESSION['children'].'","'.$_SESSION['room_id'].'", "$title" ," $first_name" , "$last_name" , "$address" , "$city" , "$state" , "$zip" , "$telephone" , "$email")';
答案 1 :(得分:0)
您的查询中的问题:
SESSION
值。$mysqli_error()
您需要删除$
签名。修改后的查询:
$insert_sql = "INSERT INTO booked_rooms (date_start, date_end, adults, children, fk_room_id, title, first_name, last_name, address, city, state_province, zip_postal, telephone, email)
VALUES ('".$_SESSION['date_start']."','".$_SESSION['date_end']."','".$_SESSION['adults']."','".$_SESSION['children']."','".$_SESSION['room_id']."', '$title' ,'$first_name' , '$last_name' , '$address' , '$city' , '$state' , '$zip' , '$telephone' , '$email')";