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
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';
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

Well, nothing's failing, it just isn't updating anything.

 

echo ut the query after you show the effected rows.

 

If it's the same as following;

 

UPDATE users SET link_bg_size=200 WHERE user_id=3

 

Make sure user_id of 3 exists in the table

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.