ThingEngineer / PHP-MySQLi-Database-Class

Wrapper for a PHP MySQL class, which utilizes MySQLi and prepared statements.
Other
3.3k stars 1.34k forks source link

getLastErrno() not working #996

Open Brecht272727 opened 2 years ago

Brecht272727 commented 2 years ago

Hi, i using the latest version of MysqlDb.php I am using ajax with dataType 'json'. But i can't see the error message in console. See below for the ajax code i use:

if($_POST) {

  include('../lib/connection.php');

  $cname = $_REQUEST['cname'];
  $street = $_REQUEST['street'];
  $postal = $_REQUEST['postal'];
  $city = $_REQUEST['city'];
  $country = $_REQUEST['country'];
  $phone = $_REQUEST['phone'];

  if(empty($cname)) {
    $cname = NULL;
  }

  $data = array(
      'cname' => $cname,
      'street' => $street,
      'postal' => $postal,
      'city' => $city,
      'country' => $country,
      'phone1' => $phone,
      'status' => 1,
      'created' => date('Y-m-d H:i:s')
  );

  $db->insert('addresses', $data);

  if($db->getLastErrno() === 0) {
    $res = array('success' => true, 'message' => 'Leveringsadres toegevoegd');
  } else {
    $res = array('error' => true, 'message' => 'Leveringsadres niet toegevoegd: '.$db->getLastError());
  }

  echo json_encode($res);

}
            $.ajax({
                type: 'POST',
                url: 'assets/ajax/save-deliveryform.php',
                dataType: 'json',
                cache: false,
                data: $('.deliveryForm').serialize(), 
                success: function (data) {
                  console.log(data);
                },
                error: function (xhr, status, error) {
                    console.log('An error occurred');
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err);
                }
            });
Brecht272727 commented 2 years ago

@avbdr or @ThingEngineer ? Any solution?