Page 1 of 1

mysql query not being queried

Posted: Sat Jun 19, 2010 7:30 pm
by rickburgen
The second and third queries dont get implemented, even though the if statement is true. Can anybody see something wrong in the code?

Code: Select all

<?php

$password = crypt($_GET["pword"]);
$code = $_GET["code"];

$connection = mysql_connect("************","*********","********");

if ($connection) {
	mysql_select_db("**********", $connection);
	
	$result = mysql_query("SELECT * FROM newpassword WHERE code='$code'");//does get implemented
	$accounts = mysql_num_rows($result);
	
	if ($accounts > 0) {
		$fields = mysql_fetch_row($result);
		
		$email = $fields[1];
		
		mysql_query("UPDATE accounts SET password='$password' WHERE email='$email'");//does not get implemented
		
		mysql_query("DELETE * FROM newpassword WHERE code='$code'");//does not get implemented
		
		fopen('example.txt', 'w');//does get implemented
		
		}
	
}
mysql_close($connection);

?>

Re: mysql query not being queried

Posted: Sun Jun 20, 2010 12:07 am
by JakeJ
regarding: mysql_query("UPDATE accounts SET password='$password' WHERE email='$email'");

echo out your variable to make sure everything is set. echo out both $password and $email. Make sure they actually exist AND that you have matching data types in your database.

regarding: mysql_query("DELETE * FROM newpassword WHERE code='$code'");//does not get implemented

You have the syntax wrong. The DELETE command deletes the whole record so you don't need the *.

Try this instead: mysql_query("DELETE FROM newpassword WHERE code='$code'");