简体   繁体   中英

MySQL query to get the primary key(customer_id) from a table and to compare it with the current session id(customer_id)

i' having this error when i run this code.

Parse error: syntax error, unexpected '" "' (T_CONSTANT_ENCAPSED_STRING) in C:\\xampp\\htdocs\\pta\\cc11205\\booking.php on line 32

 $querycust = mysql_query(" SELECT * FROM customer WHERE customer_id = ".$_SESSION['customer_id']" ");

tq.

您的查询中存在语法错误,请将查询更改为此

$querycust = mysql_query(" SELECT * FROM customer WHERE customer_id = '".$_SESSION['customer_id']."' ");

you are lacking concatenation symbol in the string. for clarity i'll rather store the seesion in a variable, eg

$session_var = $_SESSION['customer_id'];
$querycust = mysql_query(" SELECT * FROM customer WHERE customer_id = $session_var");

consider also using PDO or MySQLI extension to prevent from SQL Injection .

逃避您的报价。

" SELECT * FROM customer WHERE customer_id = \".$_SESSION['customer_id']\" "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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