/ Published in: Other
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php // Define incoming data $atm = $_REQUEST['atm']; $access = $_REQUEST['access']; $loan = $_REQUEST['loan']; $checking = $_REQUEST['checking']; $online = $_REQUEST['online']; $advantage = $_REQUEST['advantage']; $contact_name = $_REQUEST['contact_name']; $contact_email = $_REQUEST['contact_email']; $contact_zip = $_REQUEST['contact_zip']; // Validate Data if(!$atm || !$access || !$loan || !$checking || !$online || !$advantage || !$contact_name || !$contact_email || !$contact_zip){ ob_end_clean(); header("Location: http://www.anywhere_you_want.com/error"); exit(); }else{ // Define database connection $db_host = 'localhost'; $db_name = 'DB NAME'; $db_user = 'YOUR USER NAME'; $db_pass = 'YOUR PASSWORD'; $db_table = 'DB TABLE'; // Connect to database $link = mysql_connect($db_host, $db_user, $db_pass); $db = mysql_select_db($db_name); // Generate a sql statement $sql = "INSERT INTO $db_table (id, date_saved, atm, access, loan, checking, online, advantage, contact_name, contact_email, contact_zip) VALUES ('', NOW(), "; $sql .= "'" . mysql_real_escape_string($atm) . "', "; $sql .= "'" . mysql_real_escape_string($access) . "', "; $sql .= "'" . mysql_real_escape_string($loan) . "', "; $sql .= "'" . mysql_real_escape_string($checking) . "', "; $sql .= "'" . mysql_real_escape_string($online) . "', "; $sql .= "'" . mysql_real_escape_string($advantage) . "', "; $sql .= "'" . mysql_real_escape_string($contact_name) . "', "; $sql .= "'" . mysql_real_escape_string($contact_email) . "', "; $sql .= "'" . mysql_real_escape_string($contact_zip) . "'"; $sql .= ")"; // Execute the statement $result = mysql_query($sql, $link); // Now send an email to the admin $email_recipient = 'YOUR EMAIL HERE'; $email_subject = 'Quiz Response from ' . $contact_name; $email_body = 'You received a quiz response on ' . date('m/d/Y') . ' at ' . date('H:i:s') . "n"; $email_body .= "------------------------------------------------------" . "n"; $email_body .= "Contact Name : " . $contact_name . "n"; $email_body .= "Contact Email : " . $contact_email . "n"; $email_body .= "Contact Zip : " . $contact_zip . "n"; $email_body .= "------------------------------------------------------" . "n"; $email_body .= "ATM Response : " . $atm; if($atm == "75,000"){$email_body .= " - Correct";} else {$email_body .= " - Incorrect";} $email_body .= "n"; $email_body .= "Access Response : " . $access; if($access == "All of the above"){$email_body .= " - Correct";} else {$email_body .= " - Incorrect";} $email_body .= "n"; $email_body .= "Loan Response : " . $loan; if($loan == "All of the above"){$email_body .= " - Correct";} else {$email_body .= " - Incorrect";} $email_body .= "n"; $email_body .= "Checking Response : " . $checking; if($checking == "Yes"){$email_body .= " - Correct";} else {$email_body .= " - Incorrect";} $email_body .= "n"; $email_body .= "Online Response : " . $online; if($online == "No"){$email_body .= " - Correct";} else {$email_body .= " - Incorrect";} $email_body .= "n"; $email_body .= "Advantage Response : " . $advantage; if($advantage == "All of the above"){$email_body .= " - Correct";} else {$email_body .= " - Incorrect";} $email_body .= "n"; $email_body .= "------------------------------------------------------" . "n"; // SEND THE EMAIL mail($email_recipient, $email_subject, $email_body); ?>