"; print "
"; print ""; print ""; print ""; // Set the database access information as constants: DEFINE ('DB_USER', 'rcfraley'); DEFINE ('DB_PASSWORD', '*PASSWORD*'); DEFINE ('DB_HOST', 'yourpersonality.netfirmsmysql.com'); DEFINE ('DB_NAME', 'ullman'); // Make the database connection: $dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() ); /* ================================== Using mysqli_real_escape_string ================================== */ $user_id = mysqli_real_escape_string($dbc, trim($user_id)); // Define a SQL query // We will select from the data table (survey2) the user's responses to each of the five // emotion states and the submission_date. // We only select these data from rows in which // the core_user_id == the user_id in the cookie. $q = "SELECT v01,v02,v03,v04,v05,submission_date FROM survey2 WHERE core_user_id='$user_id'"; $r = @mysqli_query ($dbc, $q); // Run the query. $n_observations = 0; print ""; print "
"; print "Welcome, $first_name!

"; print "Here is an overview and summary of your entries thus far.

"; print "
"; print ""; print " "; while($row = mysqli_fetch_array($r, MYSQLI_BOTH)){ // Display previous data // In a table, we print a colored square if the person endorsed the item. // Otherwise, we present nothing. print ""; print ""; if($row[0]>=1){ print ""; }else{ print ""; } if($row[1]>=1){ print ""; }else{ print ""; } if($row[2]>=1){ print ""; }else{ print ""; } if($row[3]>=1){ print ""; }else{ print ""; } if($row[4]>=1){ print ""; }else{ print ""; } print ""; // Computations to summarize data // Simply add one to a running total for each emotion state each time it occurs. $mood1 = $mood1 + $row[0]; $mood2 = $mood2 + $row[1]; $mood3 = $mood3 + $row[2]; $mood4 = $mood4 + $row[3]; $mood5 = $mood5 + $row[4]; // Update number of observations so we can compute // a percentage later. $n_observations = $n_observations + 1; } // end while // Compute proportion of times the person reported each affective state. $mood1 = round($mood1/$n_observations,2); $mood2 = round($mood2/$n_observations,2); $mood3 = round($mood3/$n_observations,2); $mood4 = round($mood4/$n_observations,2); $mood5 = round($mood5/$n_observations,2); // Display summaries print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print "
Date Tired Hungry Anxious Sad Excited
$row[5]
Overall$mood1$mood2$mood3$mood4$mood5
"; print "
"; print "

Return to menu "; print "
"; // Close the database connection. mysqli_close($dbc); ?>