Jump to content

PHP wont update MYSQL!


vicodin

Recommended Posts

I am getting a MYSQL Syntax error. I cant figure out what is wrong... can anyone help?

 

mysql_select_db("MyTable") or die(mysql_error());
mysql_query("UPDATE products SET cat = '{$cat}', subcat = '{$subcat}', 
proname ='{$pname}', model = '{$model}', prodes ='{$pdes}', proid ='{$pid}', keywords ='{$pkey}', specs ='{$pspec}' WHERE proid = '$pid' ") or die (mysql_error());

 

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 'products WHERE proid = '10057'' at line 1

Link to comment
https://forums.phpfreaks.com/topic/137830-php-wont-update-mysql/
Share on other sites

mysql_select_db("MyTable") or die(mysql_error());
mysql_query("UPDATE products SET cat = '$cat', subcat = '$subcat', proname ='$pname', model = '$model', prodes ='$pdes', proid ='$pid', keywords ='$pkey', specs ='$pspec' WHERE proid = '$pid' ") or die (mysql_error());

 

Try that.

 

Create your query as a string variable and echo to the page when there is an error. Makes debugging much easier:

 

mysql_select_db("MyTable") or die(mysql_error());

$query = "UPDATE products
          SET cat = '{$cat}', subcat = '{$subcat}', proname ='{$pname}',
              model = '{$model}', prodes ='{$pdes}', proid ='{$pid}',
              keywords ='{$pkey}', specs ='{$pspec}'
          WHERE proid = '$pid' ";

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

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.