Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
56.2k views
in Technique[技术] by (71.8m points)

php - MySQL the right syntax to use near '' at line 1 error

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

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

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

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

$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());
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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

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

Example:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...