"; // Pass = 1 /* if($pass == 1){ // Pull out user's first name form cookie. $fn = $_COOKIE['first_name']; print "
"; print "
"; print "

Hello, $fn.

Test page for basic information.

"; print " Your email address:
Please send me e-mail notifications when a new survey is available.

Note: We will not share your e-mail address with anyone else. Your email will be used exclusveily to notify you of updates or to confirm changes to your password.
"; print ""; // Pass this manually print " "; print "Return to menu"; print "
"; print "
"; } // End pass == 1 */ if($pass == 2){ $user_id = $_COOKIE['user_id']; $sessionID = $_COOKIE['sessionID']; // Create a string that represents the database querry $q = "SELECT email, session, notifications FROM users WHERE user_id='$user_id' AND session='$sessionID'"; // Run the query $r = @mysqli_query ($dbc, $q); $results = mysqli_fetch_array($r, MYSQLI_BOTH); $email = $results[0]; $stored_notifications = $results[2]; // Let's determine if the user wants to change his or her email address. // If so, then the entered_email should be different from the email on file. // If that is true, then create a flag called $change_email and set it to 1. // !== vs. != (type conversion) // Change email if($email !== $entered_email && $sessionID == $results[1]){ $change_email = 1; } // Change notification status if($email_notifications != $stored_notifications && $sessionID == $results[1]){ $change_notifications = 1; } /* If the person entered a new email address (as determined by a difference between the email on file and the one submitted, move forward. */ if($change_email == 1){ /* First we need to check if the new email address already exists in the database. If it does, then we cannot use it because we want each user to be unique. */ $q = "SELECT user_id FROM users WHERE email='$entered_email'"; $r = @mysqli_query ($dbc, $q); // Run the query. if ($r) { // If it ran OK. // do nothing }else{ print "Error querring database. Please contact the site administrator.
"; } $num = mysqli_num_rows($r); if($num > 0){ $error[] = "An account with that email address already exists. You will need a unique email address."; }else{ // If entered email doesn't exist already, update the user's email field /* Keep in mind we only reach this part if (1) the person entered an email address that differs from what is on file, (b) the new email does not already exist in the database. As an extra precaution, we require via the query statement user_id on file equal that in cookie and ditto with respect to session ID. And email stored equals old email. */ // Construct query $q2= "UPDATE users SET email='$entered_email' WHERE user_id='$user_id' AND session='$sessionID' AND email='$email' LIMIT 1"; // Run the query $r2 = @mysqli_query ($dbc, $q2); if ($r2) { // If it ran OK. $msg[] = "The email address we have for you on file was updated. You will need to use the updated address next time you login."; }else{ print "There was an error in the data base Q2. Please contact the site administrator.
"; } } } // end if change_email /* Update notifications */ if($change_notifications == 1){ // Construct query $q2= "UPDATE users SET notifications='$email_notifications' WHERE user_id='$user_id' AND session='$sessionID' LIMIT 1"; // Run the query $r2 = @mysqli_query ($dbc, $q2); if ($r2) { // If it ran OK. if($email_notifications == 1){ $msg[] = "Your notificiation information has been updated. You will receive notifications via email when there is a new survey available on our website."; }else{ $msg[] = "Your notificiation information has been updated. You will NOT receive notifications via email when there is a new survey available on our website."; } }else{ print "There was an error in the data base Q2. Please contact the site administrator.
"; } } // end $change_notifications } // End pass == 2 // Pull out user's first name form cookie. $fn = $_COOKIE['first_name']; // Create a string that represents the database querry $q = "SELECT email, session, notifications FROM users WHERE user_id='$user_id' AND session='$sessionID'"; // Run the query $r = @mysqli_query ($dbc, $q); $results = mysqli_fetch_array($r, MYSQLI_BOTH); $email = $results[0]; $stored_notifications = $results[2]; print "
"; print "
"; print "

Hello, $fn.

Test page for basic information.

"; print " Your email address:
"; // Set the checkbox to be off by default. But turn it on // if notifications are turned on in the database $checkedstatus = ""; if($stored_notifications == 1){ $checkedstatus="checked"; } print " Please send me e-mail notifications when a new survey is available.

Note: We will not share your e-mail address with anyone else. Your email will be used exclusveily to notify you of updates or to confirm changes to your password.

"; print ""; // Pass this manually print " "; print "Return to menu"; print "
"; if(!empty($error)){ print "

The following errors occurred:
"; foreach($error as $note){ print "
    $note
"; } print "
"; } if(!empty($msg)){ print "


"; foreach($msg as $note){ print "
    ✔ $note
"; } print "
"; } print "
"; // Close the database connection. mysqli_close($dbc); ?>