MySQL在第1行错误附近使用正确的语法

时间:2021-12-20 01:07:40

hello i have a run a query using php it give error

你好,我有一个运行查询使用PHP它给出错误

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 '' at line 1

您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在第1行的''附近使用正确的语法

but when i echo the query and run manually using sqlyog software it runs fine. can anyone say whats the problem on here this is my generated query

但当我回显查询并使用sqlyog软件手动运行时它运行正常。任何人都可以说这是问题,这是我生成的查询

INSERT INTO wp_bp_activity
            (
            user_id,
             component,
             `type`,
             `action`,
             content,
             primary_link,
             item_id,
             secondary_item_id,
             date_recorded,
             hide_sitewide,
             mptt_left,
             mptt_right
             )
             VALUES(
             1,'activity','activity_update','<a title="admin" href="http://brandnewmusicreleases.com/social-network/members/admin/">admin</a> posted an update','<a title="242925_1" href="http://brandnewmusicreleases.com/social-network/wp-content/uploads/242925_1.jpg" class="buddyboss-pics-picture-link">242925_1</a>','http://brandnewmusicreleases.com/social-network/members/admin/',' ',' ','2012-06-22 12:39:07',0,0,0
             )

and here is my php code

这是我的PHP代码

$qr2="INSERT INTO wp_bp_activity
            (
            user_id,
             component,
             `type`,
             `action`,
             content,
             primary_link,
             item_id,
             secondary_item_id,
             date_recorded,
             hide_sitewide,
             mptt_left,
             mptt_right
             )
             VALUES(
             $cid,'activity',
             'activity_update',
             '<a href=\"http://brandnewmusicreleases.com/social-network/members/$name/\" title=\"$name\">$name</a> posted an update',
             '<a class=\"buddyboss-pics-picture-link\" href=\"http://brandnewmusicreleases.com/social-network/wp-content/uploads/$imgname\" title=\"$ionlyname\">$ionlyname</a>',
             'http://brandnewmusicreleases.com/social-network/members/$name/',
             ' ',
             ' ',
             '$time',
             0,
             0,
             0
             )";

after edited

经过编辑

echo $qr2="INSERT INTO wp_bp_activity (user_id,component,`type`,`action`,content,primary_link,item_id,secondary_item_id,date_recorded,hide_sitewide,mptt_left,mptt_right) VALUES($cid,'activity','activity_update','<a href=\"http://brandnewmusicreleases.com/social-network/members/$name/\" title=\"$name\">$name</a> posted an update','<a class=\"buddyboss-pics-picture-link\" href=\"http://brandnewmusicreleases.com/social-network/wp-content/uploads/$imgname\" title=\"$ionlyname\">$ionlyname</a>','http://brandnewmusicreleases.com/social-network/members/$name/','','','$time',0,0,0)";

mysql_query($qr2) or die(mysql_error());

2 个解决方案

#1


17  

the problem is because you have got the query over multiple lines using the " " that PHP is actually sending all the white spaces in to MySQL which is causing it to error out.

问题是因为您使用“”实际上将所有空格都发送到MySQL而导致错误输出的多行查询。

Either put it on one line or append on each line :o)

要么把它放在一条线上,要么附加在每一条线上:o)

Sqlyog must be trimming white spaces on each line which explains why its working.

Sqlyog必须修剪每条线上的空白区域,这就解释了它的工作原理。

Example:

例:

$qr2="INSERT INTO wp_bp_activity
      (
            user_id,
 (this stuff)component,
     (is)      `type`,
    (a)        `action`,
  (problem)  content,
             primary_link,
             item_id,....

#2


-2  

INSERT INTO wp_bp_activity
            (
            user_id,
             component,
             `type`,
             `action`,
             content,
             primary_link,
             item_id,
             secondary_item_id,
             date_recorded,
             hide_sitewide,
             mptt_left,
             mptt_right
             )
             VALUES(
             1,'activity','activity_update','<a title="admin" href="http://brandnewmusicreleases.com/social-network/members/admin/">admin</a> posted an update','<a title="242925_1" href="http://brandnewmusicreleases.com/social-network/wp-content/uploads/242925_1.jpg" class="buddyboss-pics-picture-link">242925_1</a>','http://brandnewmusicreleases.com/social-network/members/admin/',' ',' ','2012-06-22 12:39:07',0,0,0
             )

#1


17  

the problem is because you have got the query over multiple lines using the " " that PHP is actually sending all the white spaces in to MySQL which is causing it to error out.

问题是因为您使用“”实际上将所有空格都发送到MySQL而导致错误输出的多行查询。

Either put it on one line or append on each line :o)

要么把它放在一条线上,要么附加在每一条线上:o)

Sqlyog must be trimming white spaces on each line which explains why its working.

Sqlyog必须修剪每条线上的空白区域,这就解释了它的工作原理。

Example:

例:

$qr2="INSERT INTO wp_bp_activity
      (
            user_id,
 (this stuff)component,
     (is)      `type`,
    (a)        `action`,
  (problem)  content,
             primary_link,
             item_id,....

#2


-2  

INSERT INTO wp_bp_activity
            (
            user_id,
             component,
             `type`,
             `action`,
             content,
             primary_link,
             item_id,
             secondary_item_id,
             date_recorded,
             hide_sitewide,
             mptt_left,
             mptt_right
             )
             VALUES(
             1,'activity','activity_update','<a title="admin" href="http://brandnewmusicreleases.com/social-network/members/admin/">admin</a> posted an update','<a title="242925_1" href="http://brandnewmusicreleases.com/social-network/wp-content/uploads/242925_1.jpg" class="buddyboss-pics-picture-link">242925_1</a>','http://brandnewmusicreleases.com/social-network/members/admin/',' ',' ','2012-06-22 12:39:07',0,0,0
             )