HELLO EVERYONE I HAVE A HTML FORM ON A HTML PAGE FOR USE AS A FEEDBACK FORM. I WANT TO WRITE THE USER-ENTERED DETAILS INTO A MYSQL DATABASE I AM USING A WEB HOSING SERVICE WHO HAVE TOLD ME THAT TO CONNECT TO THE DATABASE I NEED TO USE PDO (PHP DATABASE OBJECT). HERE IS MY PRESENT PHP CODING TO DO THIS TASK AS OF DATE:
<?php
if(isset($_POST['email'])) {
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['firstname']) ||
!isset($_POST['lastname']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['bustype']) ||
!isset($_POST['description'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$firstname = $_POST['firstname']; // required
$lastname = $_POST['lastname']; // required
$email = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$bustype = $_POST['bustype']; // required
$description = $_POST['description']; // required
$con = new PDO("mysql:host=mysql.hostinger.in;dbname=databasename",'username', 'password');
$query = "INSERT INTO `databasename` (`id`, `firstname`, `lastname`, `bustype`, `email`, `telephone`, `description`, `timestamp`,) VALUES (NULL, '$firstname', '$lastname', '$bustype', '$email', '$telephone', '$description', CURRENT_TIMESTAMP,)";
$q = $con->prepare($query);
$q->execute(array(':$firstname' => $_POST['firstname'], ':$lastname' => $_POST['lastname'], ':$bustype' => $_POST['bustype'], ':$email' => $_POST['email'],':$telephone' => $_POST['telephone'], ':$description' => $_POST['description'], ));
echo "<h2>Thank you for filling in our contact. We shall get back to you as soon as possible.</h2>";
$con = null;
?>
but I AM GETTING AN ERROR MESSAGE WHEN I TRY TEST THE HTML FORM PAGE WHICH SAYS
PHP Code:
Parse error: syntax error, unexpected $end in /home/u196883532/public_html/form.php on line 69
PLUS THERE IS NO DATA WRITTEN TO THE DATABASE. I NEED HELP. WHAT CAN I DO? THANKS