Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL insert syntax error in pre-written script

I'm using a modified version of a pre-written script. It works in other places on the site but I can't work out what I've missed here...

    $insertQuery = "INSERT INTO cmsportfolio (status,title,imgurl,imgthumb,section,url,`desc`,type) VALUES (".
    "'".$HTTP_POST_VARS['status']."', ".
     "'".$HTTP_POST_VARS['title']."', ".
    "'".addslashes($HTTP_POST_VARS['imgurl'])."', ".
    "'".addslashes($HTTP_POST_VARS['imgthumb'])."', ".
    "'".$HTTP_POST_VARS['section'].", ".
    "'".addslashes($HTTP_POST_VARS['url'])."', ".
    "'".addslashes($HTTP_POST_VARS['desc'])."', ".
    "'".$HTTP_POST_VARS['type']."' )";


if ($result = $connector->query($insertQuery)){

    header('Location: ' . $_SERVER['PHP_SELF'].'?action=addsuccess');
    exit;

}else{
    echo "Error message = ".mysql_error(); 
    exit('<center>Sorry, there was an error saving to the database</center>');
}

I get the error message:

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 'http://www.xxxxxxxx.co.uk', 'frgdr tr tr', '0' )' at line 1 Sorry, there was an error saving to the database

(the error refers to the last 3 fields of the query)

like image 824
Doooder Avatar asked Jun 03 '26 00:06

Doooder


1 Answers

 "'".$HTTP_POST_VARS['section'].", ".

Missing ending quote

like image 107
Sparky Avatar answered Jun 05 '26 14:06

Sparky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!