Jump to content

[SOLVED] You have an error in your SQL syntax


Thomisback

Recommended Posts

Hi,

 

I get an error when executing my query but I don't get why, can someone please correct me?

 

$title = "Thomisback";

mysql_query("INSERT INTO `cscart_product_descriptions` (`product_id`, `lang_code`, `product`, `shortname`, `short_description`, `full_description`, `meta_keywords`, `meta_description`, `search_words`, `page_title`) VALUES 
($productid, 'EN', '$title', '', '', '', '$title', '$title', '$title', '$title'),
($productid, 'NL', '$title', '', '', '', '$title', '$title', $title'', '')")or die(mysql_error());

 

The error I get:

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 3

Make your life easier and create your query as a variable so you echo it to the page when an error occurs:

 

<?php
$title = "Thomisback";

$query = "INSERT INTO `cscart_product_descriptions`
            (`product_id`, `lang_code`, `product`, `shortname`,
             `short_description`, `full_description`, `meta_keywords`,
             `meta_description`, `search_words`, `page_title`)
          VALUES 
            ($productid, 'EN', '$title', '',
             '', '', '$title',
             '$title', '$title', '$title'),
            ($productid, 'NL', '$title', '',
             '', '', '$title', '$title',
            $title'', '')";

mysql_query($query) or die ("Query:<br />$query<br />Error:<br />".mysql_error());
?>

 

You would probably then see that the error is at the very end of the query:

            ($productid, 'NL', '$title', '',

             '', '', '$title', '$title',

            $title'', '')

There's a missing comma.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.