mySQL:YA 无效的查询语法错误
这给了我一个“无效语法”错误。这有什么不对呢?
$companyName = 'big company';
$address1 = 'big bay #8';
$address2 = 'some big warehouse';
$city = 'big city';
$province = 'AB';
$postalCode = 'T1T0N0';
$phone = '0123456789';
$email2 = '[email protected]';
$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),名称正确并且序列正确(并不是坏序列会破坏它......)。
我缺少什么? ...不,连接没有拼写错误...
this gives me an 'invalid syntax' error. what's so invalid about it?
$companyName = 'big company';
$address1 = 'big bay #8';
$address2 = 'some big warehouse';
$city = 'big city';
$province = 'AB';
$postalCode = 'T1T0N0';
$phone = '0123456789';
$email2 = '[email protected]';
$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();
}
i've triple checked the table and it's basically all VARCHAR(50), the names are correct and the sequence is correct (not that bad sequence would break it...).
What am I missing? ... and NO, connexion is NOT misspelled...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您有一堆字符串变量,应该用单引号括起来(并正确转义)。
You have a bunch of string variables that should be enclosed in single quotes (and properly escaped).
您正在插入文本,而不是用单引号将文本引起来。强烈建议您更改为使用参数化查询。
You're inserting text and not surrounding the text with single quotes. Highly recommend that you change to using a parameterized query.