Jump to content

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


oni-kun

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:

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.