MySQL查询从表中获取主键(customer_id)并将其与当前会话ID(customer_id)进行比较

时间:2013-05-11 16:57:30

标签: php sql

我运行此代码时出现此错误。

解析错误:第32行的C:\ xampp \ htdocs \ pta \ cc11205 \ booking.php中的语法错误,意外的“”“(T_CONSTANT_ENCAPSED_STRING)

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

TQ

3 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

你在字符串中缺少连接符号。为清楚起见,我宁愿将seeion存储在一个变量中,例如

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

还考虑使用PDOMySQLI扩展名来阻止SQL Injection

答案 2 :(得分:0)

逃避你的报价。

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