Jump to content


Photo

Update code. Solved.


  • Please log in to reply
4 replies to this topic

#1 yungbloodreborn

yungbloodreborn
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts
  • LocationCalifornia

Posted 06 October 2006 - 06:29 PM

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

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.


#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 06 October 2006 - 08:50 PM

Check mysql_error() and see what you get. 
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 yungbloodreborn

yungbloodreborn
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts
  • LocationCalifornia

Posted 07 October 2006 - 12:02 AM

$sql = mysql_query("UPDATE users SET email_address='$new_email_address', info='$info2' WHERE 

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

echo $sql;
It prints a 1 for the $sql, and nothing for the mysql_error

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 09 October 2006 - 05:38 AM

Well, then your UPDATE is "successful"... that is, no errors were generated.  Are you sure that the $username can be found?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 yungbloodreborn

yungbloodreborn
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts
  • LocationCalifornia

Posted 09 October 2006 - 07:10 PM

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!! :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users