13

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

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

但是当我回显查询并使用 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
             )

这是我的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
             )";

编辑后

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());
4

2 回答 2

21

问题是因为您使用“”在多行上进行了查询,PHP 实际上将所有空格发送到 MySQL,这导致它出错。

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

Sqlyog 必须修剪每一行上的空白,这解释了它为什么工作。

例子:

$qr2="INSERT INTO wp_bp_activity
      (
            user_id,
 (this stuff)component,
     (is)      `type`,
    (a)        `action`,
  (problem)  content,
             primary_link,
             item_id,....
于 2012-06-22T11:58:43.010 回答
-3
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
             )
于 2014-03-13T11:18:46.273 回答