简体   繁体   中英

Passing php variable in MySQL query

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=

$_email= $connection-> real_escape_string("abc@yahoo.com"); 

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

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

What seems to be the error in the SELECT statement in the php/mysql query above ?

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

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

In your code you using EMAIL = ".$_email; which is wrong at least wrap the $_eamil with single Quotes

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

Link

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

Guess what ? The answer was right there, it was that I was just missing `` for Table Name and the field.

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

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

Part of the answer was here :-

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

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