mysql语法有问题吗?

时间:2013-03-16 06:46:24

标签: php mysql

mysql语法有问题,我相信语法是正确的虽然我不断收到错误但是当我运行我的网站时出现语法错误

   $query = "SELECT DISTINCT paycheck.jobId
      FROM paycheck,users
      WHERE users.email = " . $_SESSION['email'] .
      "AND userId = empId";

2 个答案:

答案 0 :(得分:5)

你在这里忘了单引号

$query = "SELECT DISTINCT paycheck.jobId
FROM paycheck,users
WHERE users.email = '" . $_SESSION['email'] ."' AND userId = empId";

答案 1 :(得分:0)

试试这个:

$query = "SELECT DISTINCT `paycheck`.`jobId`
      FROM `paycheck`,`users`
      WHERE `users`.`email` = '" . $_SESSION['email'] ."' AND `userId` = 'empId' ";

您也可以考虑转义查询以防止sql注入