Page 1 of 1

updating database..help pls.. [SOLVED]

Posted: Mon Jan 30, 2006 10:54 am
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..

Posted: Mon Jan 30, 2006 10:56 am
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]";

Posted: Mon Jan 30, 2006 11:00 am
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)

Posted: Mon Jan 30, 2006 11:03 am
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.. :)

Posted: Mon Jan 30, 2006 11:05 am
by pleigh
oh...that's why..hehe, thanks pimp...before i can asked a question, u have already answered it... :D ...