I am trying to use $dbc->connect_error
to check if any error occurs while trying to connect to my databease. I always get an error page saying:
Here is what your code should be
setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// filtering omitted
if(!empty($main_class)){
$query = "INSERT INTO products (main_class, brand, model, description, quantity, adding_date, sell_price, buying_price ) VALUES (?,?,?,?,?,?,?,?);";
$data = [$main_class,$brand,$model,$description,$quantity,$adding_date,$sell_price,$buying_price];
$dbc->prepare($query)->execute($data);
echo "Thank you. The record has been sent successfully.
";}
else{
echo 'Please use the contact form or don\'t leave an empty field!
';
}
PDO will report it's errors already, without any extra code required.
and you should be using prepared statements