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 . "Greenscape Environmental Experience & Learning Survey Experiments