Hi, Cups, and thanks for your reply.
Yes, the database writer script does receive actual values from the main confirmform.php script that validates form submissions. I have a try-catch in there, too, to try to catch a PDOException, but I’m not seeing any data reported back.
confirmform.php
<?php
$instance = new CheckForm;
$instance -> checkSubmission();
class CheckForm
{
public function checkSubmission()
{
$origEmail = $_POST['origEmail'];
$confirmEmail = htmlspecialchars($_POST['confirmEmail']);
$name = htmlspecialchars($_POST['name']);
$ageRange = $_POST['age'];
$gender = $_POST['gender'];
$country = $_POST['country'];
$catcher = htmlspecialchars($_POST['catcher']);
$mathAnswer = htmlspecialchars($_POST['addition']);
$rightAnswer = $_POST['mathAnswer'];
$submissionTime = $_POST['submissionTime'];
$status = 0;
$response = array("validation" => " ", "message" => " ", "database" => " ");
if ($submissionTime >= 10000){
if($mathAnswer === $rightAnswer){
if (empty($confirmEmail) && empty($name) && $country === "Select Country") {
$response = array("validation" => "fail", "message" => "That's not a valid submission.");
} elseif (empty($confirmEmail) && $country === "Select Country"){
$response = array("validation" => "fail", "message" => "Please confirm your e-mail and select a location.");
} elseif (empty($name) && $country === "Select Country"){
$response = array("validation" => "fail", "message" => "Please enter a name and select a location.");
} elseif (empty($name)) {
$response = array("validation" => "fail", "message" => "Please enter a name.");
} elseif (empty($confirmEmail)) {
$response = array("validation" => "fail", "message" => "No confirmation e-mail was entered.");
} elseif ($origEmail != $confirmEmail) {
$response = array("validation" => "fail", "message" => "E-mail addresses don't match.");
} elseif ($country === "Select Country") {
$response = array("validation" => "fail", "message" => "Please select a location.");
} elseif (!empty($catcher)) {
$response = array("validation" => "fail", "message" => "Bot submission.");
} else
$status = 1;
} else
$response = array("validation" => "fail", "message" => "Math answer is incorrect.");
} else
$response = array("validation" => "fail", "message" => "Woah! Slow down and fill out the form.");
if ($status === 1) {
require_once("categoryfinder.php");
$categoryFinder = new CategoryFinder;
$category = $categoryFinder -> getCategory();
$response = array("validation" => "pass", "message" => "Thanks for joining the e-mail list, <b>" . $name . "</b>, under the e-mail address, <b>" . $confirmEmail . "</b>.", "database" => "pass");
try{
require_once('databasewriter.php');
$dbWriter = new DatabaseWriter;
$dbWriter -> writeUserToDatabase($confirmEmail, $name, $ageRange, $gender, $country, $category);
} catch (PDOException $e) {
$response = array("validation" => "pass", "message" => "Thanks for joining the e-mail list, <b>" . $name . "</b>, under the e-mail address, <b>" . $confirmEmail . "</b>.", "database" => "fail");
}
}
echo json_encode($response);
}
}
?>
However, I am confused as to step #3 and #4.
#3 Pertaining to turning on error reporting- do you mean to turn XAMPP (local server) error reporting on? I have no local database model set up… so I’m sure that won’t work.
#4 I amended my database writer script to turn on PDO error reporting, but I don’t see anything reported in Firebug.
<?php
class DatabaseWriter
{
public function writeUserToDatabase($email , $name , $age , $gender , $country , $category)
{
$host = '*********';
$dbname = 'emailcollection';
$user = '**********';
$password = '********';
try {
$connection = new PDO("mysql:host=".$host.";dbname=".$dbname, $user, $pass);
$connection -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$statement = $connection -> prepare("INSERT INTO emailcollection (email, name, age, gender, country, category) VALUES (:email, :name, :age, :gender, :country, :category)");
$statement -> bindParam(':email', $email);
$statement -> bindParam(':name', $name);
$statement -> bindParam(':age', $age);
$statement -> bindParam(':gender', $gender);
$statement -> bindParam(':country', $country);
$statement -> bindParam(':category', $category);
$statement -> execute();
echo "\
PDOStatement::errorInfo():\
";
$arr = $statement -> errorInfo();
print_r($arr);
$connection = NULL;
}catch (Exception $e){
error_log($e->getMessage());
}
}
}
?>