Jump to content


Photo

Help with email verification


  • Please log in to reply
2 replies to this topic

#1 elijahkan14

elijahkan14

    Newbie

  • New Members
  • Pip
  • 3 posts

Posted 18 February 2014 - 10:41 AM

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.



#2 WebStyles

WebStyles

    Advanced Member

  • Members
  • PipPipPip
  • 1,215 posts
  • LocationEurope

Posted 21 February 2014 - 04:40 PM

so basically you're saying this line does not work as expected:


mysqli_query($DB_CON,"UPDATE users SET Verified=1 WHERE Username='$USERNAME'");

it's based on the variable $USERNAME... You should check that it exists and is properly set. 


Need a Web Developer? Check out ClickWorks.org | I work on a PAY-WHAT-YOU-WANT basis (because the world needs a change)

 

"If it looks like a duck, and quacks like a duck, we have at least to consider the possibility that we have a small aquatic bird of the family anatidae on our hands!"

-- Douglas Adams


#3 Psycho

Psycho

    Advanced Member

  • Gurus
  • 10,836 posts
  • LocationCanada

Posted 21 February 2014 - 04:48 PM

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.");
        }

The quality of the responses received is directly proportional to the quality of the question asked.

I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com