这给了我一个'无效语法'错误。什么是无效的?
$companyName = 'big company';
$address1 = 'big bay #8';
$address2 = 'some big warehouse';
$city = 'big city';
$province = 'AB';
$postalCode = 'T1T0N0';
$phone = '0123456789';
$email2 = 'bigKahuna@bigKahuna.edu';
$query = "INSERT INTO clients ";
$query .= "(companyName, address1, address2, city, province, postalCode, phone, email) ";
$query .= "VALUES (". $companyName.",".$address1.",".$address2.",".$city.",".$postalCode.",".$phone.",".$email2.")";
print ($query . "<br><br>");
$result = mysql_query($query, $connexion);
if ($result)
{
// Success!
echo "Fabulous! check the DB, we did it! :D<br>";
} else {
// Fail!
echo"CRAAAAAPP! something went wrong. FIX IT! :P<br>";
echo mysql_error();
}
我已经对表格进行了三次检查,它基本上都是VARCHAR(50),名称正确且序列正确(不是错误的序列会破坏它......)。
我错过了什么? ......并且不,连接没有错误拼写......
答案 0 :(得分:2)
你有一堆字符串变量应该用单引号括起来(并正确转义)。
query = "INSERT INTO clients ";
$query .= "(companyName, address1, address2, city, province, postalCode, phone, email) ";
$companyName = mysql_real_escape_string($company_name);
//... etc - escape all other variables
$query .= "VALUES ('". $companyName."',"'.$address1."','".$address2."','".$city."','".$postalCode."','".$phone."','".$email2."')";
答案 1 :(得分:1)
您正在插入文字而不是用单引号包围文本。强烈建议您更改为使用参数化查询。