What's the error in this code
有什么错误在这段代码中
$FN=strtok($_POST['IS'],' ');
$LN=strtok(' ');
$query="SELECT person_id FROM a_person WHERE first_name=$FN AND last_name=$LN";
The Error IS Saying This I Can't Figure Out Why??
错误是说这个我弄不明白为什么??
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 'Select AND last_name=' at line 1
在SQL语法中有一个错误;检查与MySQL服务器版本对应的手册,以便在第1行使用“Select和last_name=”。
3 个解决方案
#1
2
you need to quote the $FN
and $LN
你需要引用FN和LN。
$query = "SELECT person_id FROM a_person WHERE first_name='$FN' AND last_name='$LN'";
#2
1
use explode and peel them off. also mysql escape the data:
使用爆炸,剥掉它们。
$names = explode(' ',mysql_real_escape_string($_POST['IS']));
$FN = $names[0];
$LN = $names[1];
$query="SELECT person_id FROM a_person WHERE first_name='$FN' AND last_name='$LN'";
#3
1
You need to wrap string values with single quotes.
您需要用单引号括起来字符串值。
$query = "SELECT person_id FROM a_person WHERE first_name='$FN' AND last_name='$LN'";
$query = "SELECT person_id FROM a_person,其中first_name='$FN'和last_name='$LN'";
#1
2
you need to quote the $FN
and $LN
你需要引用FN和LN。
$query = "SELECT person_id FROM a_person WHERE first_name='$FN' AND last_name='$LN'";
#2
1
use explode and peel them off. also mysql escape the data:
使用爆炸,剥掉它们。
$names = explode(' ',mysql_real_escape_string($_POST['IS']));
$FN = $names[0];
$LN = $names[1];
$query="SELECT person_id FROM a_person WHERE first_name='$FN' AND last_name='$LN'";
#3
1
You need to wrap string values with single quotes.
您需要用单引号括起来字符串值。
$query = "SELECT person_id FROM a_person WHERE first_name='$FN' AND last_name='$LN'";
$query = "SELECT person_id FROM a_person,其中first_name='$FN'和last_name='$LN'";