Im trying to show the type of error if my query fails, but is this correct?
try {
$sql = "INSERT INTO Customers (
CustomerFirstName,customerMiddleName,customerLastName,customerAddress,customerCity,customerState,customerZip,customerAreaCode,customerPhoneNo,customerDateOpened,customerDateModified,accountID
) VALUES (
'$First_Name','$Last_Name','$Middle_Name','$Address','$City','$State',$Zip,$Area_Code,$Phone,NOW(),NULL,NULL)";
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$stmt = $dbh->prepare($sql);
$stmt->execute();
$count = $stmt->rowCount();
if($count == 1) {
echo '<h2 class="bg-success" style="padding:4px"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span> Customer created</span></h2>';;
}
} catch (PDOException $e) {
echo $sql;
echo 'Exception -> '.var_dump($e->getMessage());
echo '<h2 class="bg-danger" style="padding:4px"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Customer NOT created</span></h2>';;
}
Thanks