query("SELECT email FROM user_account WHERE username !='$username' AND email = '$newEmail'"); if($result->num_rows > 0){ //email already exist $msg = "Try Again!!
This email is already registered to another account!!"; $pg_email = 1; $msg_type = 1; } else{ //update new email into database $result = $conn->query("UPDATE user_account SET email= '$newEmail' WHERE username = '$username'"); if($result){ $msg = "Your email has been Updated!"; //we also update the email of session variable to a new one $_SESSION['email'] = $newEmail; $pg_email = 0; $msg_type = 2; } else{ $msg = "Error updating record: " . $conn->error; $msg_type = 1; } // generate 'random code' function getRandomCode() { $n=10; $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $randomCode = ''; for ($i = 0; $i < $n; $i++) { $index = rand(0, strlen($characters) - 1); $randomCode .= $characters[$index]; } return $randomCode; } // check if 'Verify-Code' exist $result = $conn->query("SELECT verifyCode FROM user_account WHERE username = '$username'"); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { $verifyCode = $row["verifyCode"]; } } else{ //generate code $verifyCode = getRandomCode(); $conn->query("UPDATE user_account SET verifyCode = '$verifyCode' WHERE username = '$username'"); } if ( isset($verifyCode) ){ //Now after updating the email we email the verify code again //Send it to his new email $email = $newEmail; $name = "(no-reply) GEESE"; $subject = 'Account-Verification Code For GEESE'; $content = "

Hi " . $username . ",

We are team behined project GEESE. We would like to extend our gratitude for your joining to GEESE Surveys.

Although your account has already been setup. But we need to verify your account before you can use it.

This is just to validate your input credentials, and for security reasons and we research purposes.

Once you sign-up/sign-in for the first time you will directed to a page to activate your account by putting in a specific verify code generated from our website.

Your verification code is: ".$verifyCode."

"; include_once dir_rootPHP."php/request/send_email.php"; if($mail->send()){ $msg = $msg . "
The code has been emailed to you"; $msg_type = 2; }else{ $msg = $msg . "
Email couldn't be sent"; $msg_type = 1; } } else{ $msg = "
Error updating record: "."unable to generate/detect V-Code"; $msg_type = 1; } } } } if(isset($_POST["submitCode"])){ //Now we need to check if the verify Code is correct or not $userCode = mysqli_real_escape_string($conn,$_POST["code"]); $result = $conn->query("SELECT * FROM user_account WHERE username = '$username'"); if($result->num_rows == 1){ while($row = $result->fetch_assoc()){ if( $row["verifyCode"] == $userCode ){ $msg = "Your usercode is valid"; // V-Code is 'valid' | account is now 'active' = 1 | set V-Code = 0 if($conn->query("UPDATE user_account SET active = '1', verifyCode = 0 WHERE username = '$username'") === TRUE){ $msg = "Your account status has been updated!!"; $msg_type = 2; header('location: '.dir_root.'account/dashboard.php'); }else{ $msg = "There's an 'error' to activate your account!!"; $msg_type = 1; } }else{ $msg = "The 'Verify-Code' is incorrect!!"; $msg_type = 1; } } }else{ echo "Duplicate user accounts with same value"; } } } }else{ //That is go to the sign-up/login page header("location: index.php"); } ?> Verify Account | GEESE

Greenscape Environmental Experience & Learning Survey Experiments

Email Verification

Verify Account

Didn't receive a code? / Re-enter email?

Re-enter email

$icon = 2; $msg = "'.$msg.'"; popNotif_show($icon,$msg); '; } else if ($msg_type == 2){ //success include_once(dir_rootPHP.'_global/tools/popNotif.php'); echo ''; } } ?>