You are not even running the update query. Its just a string. You need to put it into the mysql_query function.
If you run into problems like this again, take a break and then come back and look at the code again. You will see silly mistakes like that.
You also need to rethink the activation key stuff. You are looping through all of the users just to compare a key. This should be done by the sql statement itself.
kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
Do your rows in the userinformation table have id's? In my projects I base all of my updates on ids. Since you are using an activation key, you need to compare that along with an id so its harder to crack.
Are you requiring your users to login before they update their password? (I am trying to figure out why you need the activation key stuff anyway)
kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
Ok, so its used for resetting forgotten passwords. Is the link with the activation code sent to the user by email?
I usually generate a new one and send it to them via email. Then I have a prompt telling them to change their password after they login.
Here is a better way of checking the activation key. Its easier on the database.
<?php
include 'top.inc';
include 'db_connect.php';
if ( isset( $_POST['submitted'] ) ) {
$err = 0;
$pass1 = mysql_real_escape_string( $_POST['pass1'] );
$pass2 = mysql_real_escape_string( $_POST['pass2'] );
if ( empty( $pass1 ) ) {
echo "<span class=\"error\"><p>You must type in a password</p></span>";
$err++;
}
if ( empty( $pass2 ) ) {
echo "<span class=\"error\"><p>You must confirm your password</p></span>";
$err++;
}
if ( $pass1 !== $pass2 ) {
echo "<span class=\"error\"><p>Your passwords do not match</p></span>";
$err++;
}
if ( $err == 0 ) {
$key = mysql_real_escape_string( $_GET['key'] ); //to prevent sql injection
$query = mysql_query( "SELECT COUNT(*) FROM `userinformation` WHERE `activationkey` = '{$key}' LIMIT 1" ) or die(mysql_error());
list( $total ) = mysql_fetch_row( $query );
if ( $total == 0 ) {
echo "<span class=\"error\"><p>Activation Key is invalid</p></span>";
}
else {
$pass1 = sha1( $pass1 );
$query = mysql_query( "UPDATE `userinformation` SET `password` = '{$pass1}' WHERE `activationkey` = '{$key}'" );
echo "<span class=\"error\"><p>Your password has been successfully updated</p><p>You will automatically be redirected in 5 seconds</p></span>";
redirect( "login.php",5 );
}
}
}
echo <<<HTML
<h1>Please enter a new password</h1>
<form action="verifypasswordreset.php" method="post">
New Password
<p><input type="password" name="pass1" maxlength="20" /></p>
Confirm New Password
<p><input type="password" name="pass2" maxlength="20" /></p>
<input type="submit" name="submit" value="Update My Password" />
<input type="hidden" name="submitted" value="TRUE" />
</form>
HTML;
include 'footer.inc';
?>
kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
I put a field in the database for it, like you said. I have some code that check for it and redirects to the change password area.
kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194