...

View Full Version : mysql update fails



tau9
12-26-2010, 09:20 PM
Hi, The ref is populated from a form i.e,



<?php echo $ref ?>


This then updates a mysql table and I get the message 1 record updated, but it doesn't update. Any ideas on why it doesn't update the table.



$sql="UPDATE table_one SET
ref='$ref',name='$name' WHERE ref ='$ref'";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record updated";

mysql_close($con)

?>


Not sure why it goes through but doesn't update..?

Thanks in advance.

Inigoesdr
12-26-2010, 10:10 PM
Not sure why it goes through but doesn't update..?
You aren't actually checking to see if it updated, only that the query was successfully executed. Check the number of affected rows with mysql_affected_rows() (http://php.net/mysql_affected_rows) to see if it updated.

tau9
12-27-2010, 05:19 PM
I get the following reply when clicking submit.

Updated records:-1

I am assuming this is supposed to say 1 rather than -1.

tau9
12-27-2010, 05:21 PM
Sorry forgot to add the code, I used




...
..
..
printf ("Updated records:%d\n", mysql_affected_rows());
mysql_query("COMMIT");

tau9
12-27-2010, 07:12 PM
This has been resolved thanks for your help



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum