mysql_affected_rows() returns -1 on UPDATE of column data

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
mikebr
Forum Contributor
Posts: 243
Joined: Sat Sep 28, 2002 7:05 am

mysql_affected_rows() returns -1 on UPDATE of column data

Post 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
Post Reply