此脚本应该检索已输入表单的Customer_First_Name和Customer_Last_Name的CustomerID。
$query = "SELECT CustomerID FROM customer WHERE Customer_First_Name = `.$db_customer_first_name.` AND Customer_Last_Name = `.$db_customer_last_name.`";
$result = mysql_query($query)
or die(mysql_error());
echo $result;
echo $query;
当脚本运行时,我收到此错误:
未知专栏'。克里斯托弗。'在'where子句'
查询永远不会在屏幕上打印出来。
感谢任何帮助。
答案 0 :(得分:1)
你的报价不好用'而不是勾选`
答案 1 :(得分:0)
使用'
代替`
$query = "SELECT CustomerID FROM customer WHERE Customer_First_Name = '".$db_customer_first_name."' AND Customer_Last_Name = '".$db_customer_last_name."'";
答案 2 :(得分:0)
您必须对字符串使用单引号。再试一次:
$query = "SELECT CustomerID FROM customer WHERE Customer_First_Name = '".$db_customer_first_name."' AND Customer_Last_Name = '".$db_customer_last_name."'";
答案 3 :(得分:0)
这应该有效:
$query = "SELECT CustomerID FROM customer WHERE Customer_First_Name = '$db_customer_first_name' AND Customer_Last_Name = '$db_customer_last_name'";
您需要使用正常的单引号作为值。如果您使用双引号,也不需要断开字符串 - 在字符串中检测到变量。
确保你也正确地为mysql转义字符串以防止注入。
更好的是,看看转向mysqli并使用准备好的陈述。