Page 1 of 1

mysql_affected_rows() returns -1 on UPDATE of column data

Posted: Sun Jan 18, 2004 3:46 pm
by mikebr
I have a problem using making an update query on a MySQL database using PHP. The column is VARCHAR for storing an image name, if there is no image name in the column the default value of the column will be 0. The first time the query is run the image name is entered and mysql_affected_rows() reurns 1, but if I try to replace the image name then mysql_affected_rows() returns -1. Now the image is being replaced when I run the query to replace the image so why does mysql_affected_rows() return -1?. The code is as follows.....

Code: Select all

<?php
/* Database connection stuff
$tst is set to table name depending on the table the image is being uploaded for and $image_column is set to the image that is being updated image1 to image5, column for each one  */

$query="UPDATE $tst SET $image_column ='$new_file_name' WHERE ID=$ID AND client='$client' LIMIT 1";

					if (!mysql_query($query,$connection)) {
					echo "Connection error";
					}else{
					
						if (mysql_affected_rows() >0) {
						echo "Rows where updated";
					 } else {
						echo "Rows where not updated";
						}
					}
?>
Thanks for any help on this