mySQL:YA 无效的查询语法错误

发布于 2024-12-15 00:05:56 字数 1034 浏览 0 评论 0原文

这给了我一个“无效语法”错误。这有什么不对呢?

$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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

残疾 2024-12-22 00:05:56

您有一堆字符串变量,应该用单引号括起来(并正确转义)。

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."')";

You have a bunch of string variables that should be enclosed in single quotes (and properly escaped).

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."')";
山人契 2024-12-22 00:05:56

您正在插入文本,而不是用单引号将文本引起来。强烈建议您更改为使用参数化查询。

You're inserting text and not surrounding the text with single quotes. Highly recommend that you change to using a parameterized query.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文