php通过我的查询

时间:2016-03-17 11:49:28

标签: php sql session insert

我试图将我的会话当前持有的值插入到我的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变量

2 个答案:

答案 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')";