Jump to content

[SOLVED] mysql query fails, yet no errors


evanct

Recommended Posts

So I have this simple query:

 

$sql="UPDATE users SET link_bg_size=$dimension WHERE user_id=$id";
mysql_query($sql) or die('Could not insert link_bg_size: '.mysql_error());

 

The strange part is although it isn't working(and should work), I don't get any mysql errors or even relevant php notices. I echoed $sql and it's all correct:

 

UPDATE users SET link_bg_size=200 WHERE user_id=3

 

Yet when I refresh phpmyadmin the old link_bg_size value is still there. What might be going on here?

Link to comment
https://forums.phpfreaks.com/topic/161333-solved-mysql-query-fails-yet-no-errors/
Share on other sites

-Like I said, there were no relevant php notices.

 

I asked if you had error reporting on, if you don't php errors will not be displayed (even if their fatal you'll just see a blank screen).

 

-Isn't that the purpose of 'or die()'?

 

No the purpose of or die() is different, and shouldn't be used... see this article - http://www.phpfreaks.com/blog/or-die-must-die

 

Just because the query is successful doesn't mean anything happened.

 

$result = mysql_query(your query);
if($result) {
echo 'affected rows'. mysql_affected_rows($result);
} else {
echo 'there was a problem';
}

When I say 'there were no relevant php notices' that implies that I had notices turned on but no relevant ones were displayed.

 

But anyway, I tried that and all I got was a warning telling me that the argument for mysql_affected_rows is not a valid mysql-link resource.

Sorry, my mistake;

 

mysql_affected_rows($result)

 

should be

 

mysql_affected_rows()

 

When I say 'there were no relevant php notices' that implies that I had notices turned on but no relevant ones were displayed.

 

Don't worry I was only checking. I'd look pretty stupid if we went through this and it could've been solved a lot easier, if I hadn't assumed that you had implied the above...

If $id was a string that only contained the character 3 or even if it contained '3' (including the quotes as part of the string), it would have worked. About the only way it would not work is if something else was part of the string too, such as sql escape characters or some other non-numeric leading character(s).

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.