updating database..help pls.. [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

updating database..help pls.. [SOLVED]

Post by pleigh »

i have these lines of codes

Code: Select all

if ($un && $pw && $pw1)
	{
		$query = "SELECT userID FROM users where(username='$un' AND password='$pw')";
		$result = @mysql_query($query);
		$num = mysql_num_rows($result);
		if ($num == 1)
		{
			$row = mysql_fetch_array($result, MYSQL_NUM);
			
			//make the query
			$query = "UPDATE users SET password='$pw1' WHERE userID=$row[0]";
			if (mysql_affected_rows() == 1)
			{
				echo '<p><b>Your password has been changed.</b></p>';
				include('templates/footer.inc');
				exit();
			}
			else 
			{
				$message .= '<p>Your password could not be changed due to system error</p><p>' . mysql_error() . '</p>';
			}
		}
		else 
		{
			$message .= '<p>Your username and password do not match our records!</p>';
		}
		mysql_close();
	}
	else 
	{
		$message .= '<p>Please try again!</p>';
	}
when i click the submit button, it returns the message "your password has been changed"...that's good...but the funny part is that, in my database, the password does not change...can you spot what maybe the problem??i scrolled to my book and i think i wrote the code right...

thanks in advance..
Last edited by pleigh on Mon Jan 30, 2006 11:05 am, edited 1 time in total.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

I dont know why the correct message is displayed to the screen, but you dont actually execute the following query

Code: Select all

$query = "UPDATE users SET password='$pw1' WHERE userID=$row[0]";
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

ah, just figured it...it is returning the result from the previous query.

you need this

Code: Select all

$query = "UPDATE users SET password='$pw1' WHERE userID=$row[0]"; 

$result = @mysql_query($query); 

if (mysql_affected_rows() == 1)
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

i don't know too, but that's really funny when i missed to put the code

Code: Select all

$result = @mysql_query($query);
after the $query of the update..my laziness confuses me more...but its really funny though...can someone explain why this happened??the appearance of the success message where in fact there is an error...thanks pimp for the reply.. :)
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

oh...that's why..hehe, thanks pimp...before i can asked a question, u have already answered it... :D ...
Post Reply