mysql query not being queried

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
rickburgen
Forum Newbie
Posts: 10
Joined: Thu Mar 05, 2009 5:41 pm

mysql query not being queried

Post 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);

?>
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: mysql query not being queried

Post 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'");
Post Reply