Page 1 of 1

PHP/MySQL: UPDATE issue

Posted: Wed Jun 02, 2010 7:54 pm
by TonsOfFun
I'm trying to write a script that will edit a database row but there is a problem in my code I can't seem to find. I'm sure it's obvious, but yet it eludes me.
mysql_error() won't even report anything back

Here the part that I think is causing the problem:

Code: Select all

$query = "UPDATE album_list SET album_name = '$album_name', description = '$desc', caption = '$caption' WHERE album_id = '$album_id'";
		$result = mysql_query($query) OR die (mysql_error());
				
		if(mysql_affected_rows() == 1)	{
						
			echo "<p>You have succesfully updated album <i>$album_name</i>!</p>";
			mysql_close();
			exit();
		} else {
						
			echo mysql_error();
			echo "<p>System Error! Could not update album.<br /> " . mysql_error() . "<br /><br />Query: " . $query . "</p>";
			
			mysql_close();
		}
I can add the full script if needed.

Thanks in advance for your input.

Re: PHP/MySQL: UPDATE issue

Posted: Wed Jun 02, 2010 8:52 pm
by mikosiko
and what is according to you the problem?....

Re: PHP/MySQL: UPDATE issue

Posted: Wed Jun 02, 2010 9:12 pm
by TonsOfFun
mikosiko wrote:and what is according to you the problem?....
That's the thing, I can't figure out a specific problem other than that it simply won't work.

I don't get any errors besides the one I created with the die() statement.
When I run the script, I get:
System Error! Could not update Album 1.


Query: UPDATE album_list SET album_name = 'Album Test', description = 'Test', caption = 'Testing' WHERE album_id = ''

Re: PHP/MySQL: UPDATE issue

Posted: Wed Jun 02, 2010 9:20 pm
by mikosiko
so basically your update is not affecting any row, because your WHERE clause is referencing an inexistent row most likely....
TonsOfFun wrote:WHERE album_id = ''
do you have a record with an album_id = '' ??

check the value of $album_id before to construct your $query sentence.

Re: PHP/MySQL: UPDATE issue

Posted: Wed Jun 02, 2010 9:29 pm
by TonsOfFun
Of course, simple fix.
I missed created that variable.

Thanks mikosiko.