I am trying to make an insert into my DB and checking if the $_POST global isset but do not seem to have any luck get an insert to work.
It will work if there is only one field and checking one field, but I want more than one.
Can you see what is wrong with my code please.
if (isset($_POST['name'])&& ($_POST['email']) && ($_POST['message'])){
try
{
$pdo = new PDO('mysql:host=localhost;dbname=chairkit', $user,$pass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec('SET NAMES "utf8"');
}
catch (PDOException $e)
{
$output = 'unable to connect to server'. $e->getMessage();
include './connect/output.html.php';
exit();
}
// get connection to DB
try {
$sql = "INSERT INTO comments (name,email,comment) VALUES (:name,:email,:comment)";
$s = $pdo->prepare($sql);
$s->execute(array(':name'=>$_POST['name'],
':email'=>$_POST['email'],
':comment'=>$_POST['comment']));
} catch (PDOException $e)
{
$error = 'Error inserting comments ' . $e->getMessage();
include './listcomments/error.html.php';
}
header('Location: thankyou.html');
exit();
}