Jump to content

Archived

This topic is now archived and is closed to further replies.

yungbloodreborn

Update code. Solved.

Recommended Posts

I'm not sure if this is the best place to post this question, but since it's dealing directly with mysql, it seemed right.

I have a snippet of code that says it's working, but it isn't.
[code]
$sql = mysql_query("UPDATE users SET email_address='$new_email_address', info='$info2' WHERE username='$username'");

if(!$sql){
    $message = 'There has been an error updating your profile. Please contact the webmaster.';
    include 'message.php';
} else {
    $message = 'Your profile has been updated!';
    include 'message.php';
}
[/code]

It says it updates my profile, but it doesn't. But when I run the same line directly in phpmyadmin, it works fine. I'm using one file that has all the database info (server, login, pass, table) and it works fine for everything else.

Share this post


Link to post
Share on other sites
Check mysql_error() and see what you get. 

Share this post


Link to post
Share on other sites
[code]
$sql = mysql_query("UPDATE users SET email_address='$new_email_address', info='$info2' WHERE

username='$username'") or die (mysql_error());

echo $sql;
[/code]
It prints a 1 for the $sql, and nothing for the mysql_error

Share this post


Link to post
Share on other sites
Well, then your UPDATE is "successful"... that is, no errors were generated.  Are you sure that the $username can be found?

Share this post


Link to post
Share on other sites
fenway,
  I found the problem. You pointed me in the right direction. You're right, it wasn't seeing $username because I had session_start() in the form that gets included, but not for the rest of the script. As soon as I put it at the top of this script, it worked perfectly. Thanks!! :)

Share this post


Link to post
Share on other sites

×

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.