We must ask for your name and email address to ensure that no one votes more than once, but we do not associate your personal information with your rating.
EOREGFORM; $rate_form = <<< EORATEFORMMy boss is:
EORATEFORM; if (!$_POST['submit']) { // First time, just show the registration form $message = $reg_form; } elseif ($_POST['submit'] == 'Submit' && $_POST['stage'] == 'register') { // Second time, show the registration form again on error, rating form on successful INSERT if (!$_POST['name'] || $_POST['name'] == "" || strlen($_POST['name'] > 30) || !$_POST['email'] || $_POST['email'] == "" || strlen($_POST['email'] > 30)) { $message = 'There was a problem. Did you enter a name and email address?
'; $message .= $reg_form; } else { // Open connection to database mysql_connect("localhost", "testuser", "testpass") or die("Failure to communicate with database."); mysql_select_db("testdb"); // Check to see this name and email have not appeared before $as_name = addslashes($_POST['name']); $tr_name = trim($as_name); $as_email = addslashes($_POST['email']); $tr_email = trim($as_email); $query = "SELECT sub_id FROM raters WHERE Name = '$tr_name' AND Email = '$tr_email'"; $result = mysql_query($query); if (mysql_num_rows($result) > 0) { error_log("\n1".mysql_error()."\n\n", 3, "/tmp/phplog.err"); $message = 'Someone with this name and password has already rated. If you think a mistake was made, please email admin@example.com'; } else { // Insert name and email address $query = "INSERT INTO raters (ID, Name, Email) VALUES(NULL, '$tr_name', '$tr_email')"; $result = mysql_query($query); if (mysql_affected_rows() == 1) { $message = $rate_form; } else { error_log(mysql_error()); $message = 'Something went wrong with your signup attempt.
'; $message .= $reg_form; } } } } elseif ($_POST['submit'] == 'Submit' && $_POST['stage'] == 'rate') { // Third time, store the rating and boss's name // Open connection to the database mysql_connect("localhost", "testuser", "testpass") or die("Failure to communicate with database"); mysql_select_db("testdb"); // Insert rating and boss's name $as_boss = addslashes($_POST['boss']); $tr_boss = trim($as_boss); $rating = $_POST['rating']; $query = "INSERT INTO ratings (ID, Rating, Boss) VALUES(NULL, '$rating', '$tr_boss')"; $result = mysql_query($query); if (mysql_affected_rows() == 1) { $message = 'Your rating has been submitted.
'; } else { error_log("\n".mysql_error()."\n\n", 3, "/tmp/phplog.err"); $message = 'Something went wrong with your rating attempt. Try again.
'; $message .= $rate_form; } } ?>
Rate your boss anonymously |