Jump to content

MYSQL update script only updates some records?!


Target

Recommended Posts

Hey,

 

New to this place, but I'm wondering if you could help me..... I'm making a website in PHP for my uni assignment however one of my MYSQL update scripts doesn't work right as it keeps wiping rows clean!

 

   mysql_query("UPDATE  `limetree_uni`.`Products` SET  `Product_Cat` =  '".$Product_CAT_SET."',`Product_Title` =  '".$New_Title."',`Product_Description` =  '".$New_Description."', `Product_Shipping` =  '".$New_Shipping."',
`Product_Stock` =  '".$New_Stock."', `Product_Price` =  '".$New_Price."' WHERE `PID` = ".$EID." LIMIT 1") ;

 

The $EID stands for the edit number. The above script works fine for anything that was already in the table, however for any new rows which only has a PID it wipes that record clean apart from the PID number.

 

For example: A row which can be updated fine has the PID number 30. I can edit this and nothing gets wiped but is updated as required.

 

If this PID is 31 however nothing is update and all the data within that row is wiped clean. Now if I change this troublesome row PID to 30 and I change the previous row which was 30 to 31 then the row with the PID 30 gets wiped and 31 is updated!! So it's completed reversed!

 

Can anyone see anything wrong the above code, its driving me crazy!! :shrug:

 

Cheers  :)

Try this:(presuming your assigning keys and PID is set as an index or UNIQUE

mysql_query("INSERT INTO `limetree_uni`.`Products` (`PID`,`Product_Cat`,`Product_Title`,`Product_Description`,`Product_Shipping`,`Product_Stock`,`Product_Price) VALUES ('$EID','".$Product_CAT_SET."','".$New_Title."','".$New_Description."','".$New_Shipping."','".$New_Stock."','".$New_Price."') ON DUPLICATE KEY UPDATE `Product_Cat` =  '".$Product_CAT_SET."',`Product_Title` =  '".$New_Title."',`Product_Description` =  '".$New_Description."', `Product_Shipping` =  '".$New_Shipping."',
`Product_Stock` =  '".$New_Stock."', `Product_Price` =  '".$New_Price."'");

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.