Jump to content

[SOLVED] UPDATE non functional. Any suggestions?


golgoj4

Recommended Posts

Hello.

 

Im quite new to php and have been attempting to create a simple website. The problem is, one particular script is refusing to function and I have no idea why. the code is actually used in another part of the site, and it works fine...but not on this particular bit.

 

this is the code that takes the information posted by the update page and is supposed to add it to the db.

taking some advice I read in similar threads, I added and error message which tells me :

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 ''articles' SET title='biznatch!', desc='blah blah' WHERE id='21'' at line 1

 

<?php mysql_connect($host,$userName,$pass);
$query= "UPDATE 'articles' SET title='$ud_title', desc='$ud_desc' WHERE id='$id' ";
@mysql_select_db($db) or die( "Unable to select database");
$result= mysql_query($query);

if($result) echo "Information updated" ;
else
      echo "There was a problem with your update: " . mysql_error(); ?>

 

So im quite stumped as to what im doing wrong. the variables are all populated, but I get this error unless i only update 1 column. :-\

 

thanks for any help.

Link to comment
Share on other sites

furthermore, the table name should not be enclosed in single quotes.  either do not enclose it in anything, or use back ticks for the table name as well.

 

thank you as well. I did that in a desperate attempt to change things around. Im going to make these changes and try to avoid the reserved names.

 

FIXED

 

<?php
mysql_connect($host,$userName,$pass);
$query= "UPDATE articles SET title='$ud_title', descr='$ud_descr', notes='$ud_notes' , text='$ud_text' WHERE id='$id' ";
@mysql_select_db($db) or die( "Unable to select database");
$result= mysql_query($query);

if($result) echo "Information updated" ;
else
      echo "There was a problem with your update: " . mysql_error(); ?>

 

both of your suggestions were key to fixing it. Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.