I have recently been working with PDO, so I am new to it and for some reason I can not get this to insert records into the database. What am I doing wrong here!?!?
if (isset($_POST['submit'])) {
$sql = "INSERT INTO customer(firstname,lastname,email,address,city,state,zip,phone,company)
VALUES(:firstname,:lastname,:email,:address,:city,:state,:zip,:phone,:company)";
$stmt = $db->prepare($sql);
if (!$_POST['fname'])
$errors[] = 'You must input a first name';
if (!$_POST['lname'])
$errors[] = 'You must input a last name';
if (!$_POST['address'])
$errors[] = 'You must input an address';
if (!$_POST['city'])
$errors[] = 'You must input a city';
if (!$_POST['state'])
$errors[] = 'You must input a state';
if (!$_POST['zip'])
$errors[] = 'You must input a zip';
if (!$_POST['email'])
$errors[] = 'You must input a e-mail';
if (!$_POST['phone'])
$errors[] = 'You must input a phone';
if (!$errors) {
$stmt->bindParam(':firstname', $_POST['fname'], PDO::PARAM_STR);
$stmt->bindParam(':lastname', $_POST['lname'], PDO::PARAM_STR);
$stmt->bindParam(':email', $_POST['email'], PDO::PARAM_STR);
$stmt->bindParam(':address', $_POST['address'], PDO::PARAM_STR);
$stmt->bindParam(':city', $_POST['city'], PDO::PARAM_STR);
$stmt->bindParam(':state', $_POST['state'], PDO::PARAM_STR);
$stmt->bindParam(':zip', $_POST['zip'], PDO::PARAM_STR);
$stmt->bindParam(':phone', $_POST['phone'], PDO::PARAM_STR);
$stmt->bindParam(':company', $_POST['company'], PDO::PARAM_STR);
$stmt->execute();
}
}
When I do print_r($db->errorInfo()); I get this array returned to me upon submitting
Array ( [0] => 00000 [1] => [2] => ) 1