"; // Pass = 1 if($pass == 1){ // Determine the randomized order of items $item_index = range(0,$max_index); shuffle($item_index); // Pull out user's first name form cookie. $fn = $_COOKIE['first_name']; print "
"; print "
"; print "

Hello, $fn.

This module is designed to allow you to record and track your mood over time. Simply indicate whether you are experiencing any of the following right now. You may select as many or as few responses as appropriate.

"; // Note: Because we are presenting all the items in one sweep, I do not have // hidden tag subroutines to pass things forward. Everything we need (minus pass) // is being collected here as used input and will naturally be passed forward // when the user presses submit. // Loop through all the items. Present each one with the appropriate variable name. foreach ($item_index as $key => $value){ $this_item_name = $item_names[$item_index[$key]]; // which variable name to use? $this_item_content = $item_content[$item_index[$key]]; // which item to present now? print "

$this_item_content

"; print " \n"; } print ""; // Pass this manually print ""; print "
"; print "
"; } // End pass == 1 if($pass == 2){ /* SQL code to create the table. We need to run this once in phpMyAdmin before the survey is tested/goes live. CREATE TABLE survey2 ( user_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT, v01 VARCHAR(1) NOT NULL, v02 VARCHAR(1) NOT NULL, v03 VARCHAR(1) NOT NULL, v04 VARCHAR(1) NOT NULL, v05 VARCHAR(1) NOT NULL, core_user_id VARCHAR(60) NOT NULL, submission_date DATETIME NOT NULL, PRIMARY KEY (user_id) ); */ // 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'); // Open the database connection: $dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() ); $user_id = $_COOKIE['user_id']; $sessionID = $_COOKIE['sessionID']; /* ================================== Using mysqli_real_escape_string ================================== */ $v01 = mysqli_real_escape_string($dbc, trim($v01)); $v02 = mysqli_real_escape_string($dbc, trim($v02)); $v03 = mysqli_real_escape_string($dbc, trim($v03)); $v04 = mysqli_real_escape_string($dbc, trim($v04)); $v05 = mysqli_real_escape_string($dbc, trim($v05)); $user_id = mysqli_real_escape_string($dbc, trim($user_id)); // Create a string that represents the database querry $q = "INSERT INTO survey2 (v01,v02,v03,v04,v05,core_user_id,submission_date) VALUES ('$v01','$v02','$v03','$v04','$v05','$user_id',NOW() )"; // Run the query $r = @mysqli_query ($dbc, $q); // Let's make a new query to indicate that the user has completed the survey $q2= "UPDATE users SET study2_taken='1', study2_lastdate=NOW(), study2_type='repeat' WHERE user_id='$user_id' AND session='$sessionID' LIMIT 1"; // Run the query $r2 = @mysqli_query ($dbc, $q2); if ($r) { // If it ran OK. print "Your data have been saved. Thank you for your participation!

Return to menu "; }else{ print "There was an error in the data base Q1. Please contact the site administrator.
"; } if ($r2) { // If it ran OK. //print "users updated okay "; }else{ print "There was an error in the data base Q2. Please contact the site administrator.
"; } // Close the database connection. mysqli_close($dbc); } // End pass == 2 ?>