All I'm trying to do is perform an SQL query to transfer data from each text input box in the form to a database. I keep receiving the following error for DatabaseStuff.php:
Parse error: syntax error, unexpected end of file in /home/ar04063/public_html/DatabaseStuff.php on line 38
What am I doing wrong? Is there anything else that I need to do to be getting it working properly? Here's some sample code:
XYZSurvey.php:
<?php
require_once 'Form.php';
require_once 'RadioButton.php';
require_once 'TextInput.php';
require_once 'Validator.php';
$form = new Form();
$form -> addInput(new TextInput("First Name: ", "first_name"));
$form -> addInput(new TextInput("Last Name: ", "last_name"));
$form -> addInput(new TextInput("Age: ", "ice_cream_flavor"));
$radio1 = new RadioButton("Gender:", "gender");
$radio1 -> addOption("Male", "male");
$radio1 -> addOption("Female", "female");
$form -> addInput($radio1);
$form -> addInput(new TextInput("Email: ", "email_address"));
$form -> addInput(new TextInput("", "","Submit","","",false,"submit"));
echo $form -> generateHTML();
DatabaseStuff.php:
<?php
require_once 'XYZSurvey.php';
$host = "localhost";
$username = "W********";
$password = "**********";
$dbname = "W01104063";
$firstname = $_POST["first_name"];
$lastname = $_POST["last_name"];
$email = $_POST["email"];
$gender = $_POST["gender"];
try {
$dbh = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
} catch (PDOException $e)
{
echo "Sorry, an error occured.";
echo $e->getMessage();
die();
}
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$stmtSurvey = $dbh->prepare("INSERT INTO PersonalInfo (firstname, lastname, email, gender) VALUES ('$firstname', '$lastname', '$email', '$gender');
$stmtSurvey->bindValue(':firstname', 'Ashley');
$stmtSurvey->bindValue(':lastname', 'Richardson');
$stmtSurvey->bindValue(':email', 'null');
$stmtSurvey->bindValue(':gender', 'null');
$stmtSurvey->setFetchMode(PDO::FETCH_ASSOC); //Set Fetch mode to Assoc
$stmtSurvey->execute();
while($survey = $stmtSurvey->fetch())
{
var_dump($survey);
}