PHP-MySQLi-Database-Class icon indicating copy to clipboard operation
PHP-MySQLi-Database-Class copied to clipboard

getLastErrno() not working

Open Brecht272727 opened this issue 3 years ago • 1 comments

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 avatar Sep 29 '22 14:09 Brecht272727

@avbdr or @ThingEngineer ? Any solution?

Brecht272727 avatar Sep 30 '22 18:09 Brecht272727