Jump to content

Help with email verification


elijahkan14

Recommended Posts

I'm almost there, I have two tables, one stores unverified users, the other stores all users and has a column labeled "Verified" which is either a 1 or 0.

The code is able to check the hash sent in the email link and is able to get as far as deleting the user from the "unverified" table.

The code does not change "Verified" from 0 to 1 on the "users" table.

	$SQL_REQUEST = "SELECT * FROM `unverified` WHERE `Hash`='$Hash'";
	$SQL_RESULT = mysqli_query($DB_CON, $SQL_REQUEST);
	$SQL_VALID = mysqli_num_rows($SQL_RESULT);
		if($SQL_VALID > 0){
			mysqli_query($DB_CON,"UPDATE users SET Verified=1 WHERE Username='$USERNAME'");
			mysqli_query($DB_CON,"DELETE FROM `unverified` WHERE `Hash`='$Hash'");
			echo '<p>Your account has been activated, you can now login <a href="https://www.site.org/login/">here</a></p>';
			mysqli_close($DB_CON);
			exit();
		
			}
		else{
			die("The hash and/or username you provided was incorrect. If you believe this is an error, please contact customer support.");
		}

Any help would be greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/286288-help-with-email-verification/
Share on other sites

Why do you have two tables? You state one table has a column for "verified" with a 1 or 0. Why not just use the records in that table and change that value (you'd probably just need to move the hash column there as well)? Seems like you're making this harder than it should be.

 

But, I'm betting the problem is what WebStyles stated - the variable $Username is not set. It's always a good idea to create your queries as string variables so you can verify them if needed.

 

 

    $SQL_REQUEST = "SELECT * FROM `unverified` WHERE `Hash`='$Hash'";
    $SQL_RESULT = mysqli_query($DB_CON, $SQL_REQUEST);
    $SQL_VALID = mysqli_num_rows($SQL_RESULT);
        if($SQL_VALID > 0){
            $query = "UPDATE users SET Verified=1 WHERE Username='$USERNAME'";
            echo $query; // Verify the query
            mysqli_query($DB_CON,$query);
            mysqli_query($DB_CON,"DELETE FROM `unverified` WHERE `Hash`='$Hash'");
            echo '<p>Your account has been activated, you can now login <a href="https://www.site.org/login/">here</a></p>';
            mysqli_close($DB_CON);
            exit();
        
            }
        else{
            die("The hash and/or username you provided was incorrect. If you believe this is an error, please contact customer support.");
        }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.