简体   繁体   English

PHP通过我的查询将多个会话变量插入MySQL

[英]php inserting multiple session variables into mysql through my query

I'm trying to insert the values my session is currently holding into my mysql table. 我正在尝试将我的会话当前持有的值插入到我的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());

It should work, but I'm not sure how to use the $_session variables in this context 它应该工作,但我不知道如何在此上下文中使用$ _session变量

You have some mistakes in your query. 您的查询中有一些错误。 try like this 试试这样

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

Issues in your query: 您的查询中的问题:

  • You need to split your SESSION values in commas. 您需要以逗号分隔SESSION值。
  • Use quotes for string values. 对字符串值使用引号。
  • Don't know what is it? 不知道是什么 $mysqli_error() you need to remove $ sign. $mysqli_error()你需要删除$ sign。

Modified Query: 修改后的查询:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM