在MySQL查询中传递php变量

时间:2015-12-17 22:16:07

标签: php mysql mysqli

您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在' =

附近使用正确的语法
$_email= $connection-> real_escape_string("abc@yahoo.com"); 

$checkSql  = "SELECT * ";
$checkSql .= "FROM customer_registration";
$checkSql .= "WHERE ";
$checkSql .= "EMAIL=" . $_email ;

$result = $connection-> query($checkSql); 

上面的php / mysql查询中的SELECT语句中出现了什么错误?

3 个答案:

答案 0 :(得分:0)

$checkSql  = "SELECT * ";
$checkSql .= "FROM customer_registration ";
$checkSql .= "WHERE ";
$checkSql .= "EMAIL LIKE '" . $_email ."'";

$result = $connection-> query($checkSql); 

在您的代码中使用EMAIL = ".$_email;这是错误的,至少用单引号包装$ _eamil

 $checkSql .= "EMAIL='" . $_email."'" ;

Link

答案 1 :(得分:0)

$checkSql .= "Email = \"$_email\"";

答案 2 :(得分:0)

猜猜是什么?答案就在那里,就是我只是缺少``表名和字段。

$checkSql  = "SELECT * ";
$checkSql .= "FROM `customer_registration`";
$checkSql .= "WHERE `EMAIL` = ". "'{$_email}' ";

$result = $connection-> query($checkSql); 

部分答案在这里: -

Error in your SQL syntax; check the manual that corresponds to your MySQL server version