mysql - How to insert a double quotes in a variable in php -


i trying send query this:

$sql = "select id loto_users email=".$email." limit 1"; echo $sql; //to control $result = mysql_query($sql); 

when that, returns me:

select id loto_users email=xxx@gmail.com limit 1

you have error in sql syntax; check manual corresponds mysql server version right syntax use near '@gmail.com limit 1' @ line 1

then tried run line in mysql web interface. copy-paste this:

select id loto_users email=xxx@gmail.com limit 1 

it gave me same error msg. added double quotes before , after email adress:

select id loto_users email="xxx@gmail.com" limit 1 

now, runs... in interface. want in php file have no idea how create variable capable includes double quotes.

or there other way?

just add single quotes string need:

$sql = "select id loto_users email='".$email."' limit 1"; 

but, if really want double quotes, escape them:

$sql = "select id loto_users email=\"".$email."\" limit 1"; 

or, alternatively, don't concatenation:

$sql = "select id loto_users email='$email' limit 1"; $sql = "select id loto_users email='{$email}' limit 1"; 

Comments

Popular posts from this blog

android - Automated my builds -

how to proxy from https to http with lighttpd -

python - Flask migration error -