Jump to content

Using $_POST with UPDATE query?.. think it's easy.


Recommended Posts

I have a table set where the rows are in this format:

 

ID - Done - Length - Weight

 

And there are 43 rows.. but if I wanted to update a row (from a mass of inputs)

for ($i = 0; $i <=42; $i++) {
   $sql = "
   UPDATE `personal` 
   SET done='".mysql_real_escape_string(Checkboxfilter($_POST['done'], "$i"))."', //returns yes/no
   length='".mysql_real_escape_string($_POST['len'][$i])."',
   weight='".mysql_real_escape_string($_POST['weight'][$i])."',
   WHERE id='".$i."'
   ";
   mysql_query($sql) or die('MYSQL Erorr:' . mysql_error());
}

 

It gives me this error:

MYSQL Erorr: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 'WHERE id='0'' at line 5

 

Is there a problem with using WHERE id=$id in the update command?  :confused:

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.