prepare("SELECT * FROM driver WHERE phone = :phone OR email = :email"); $stmt->bindParam(':phone', $inputData['phone'], PDO::PARAM_STR); $stmt->bindParam(':email', $inputData['email'], PDO::PARAM_STR); $stmt->execute(); if ($stmt->rowCount() > 0) { printFailure("The email or phone number is already registered."); } // Prepare SQL for inserting new driver $sql = " INSERT INTO `driver` ( `id`, `phone`, `email`, `password`, `gender`, `license_type`, `national_number`, `name_arabic`, `name_english`, `issue_date`, `expiry_date`, `license_categories`, `address`, `card_id`, `occupation`, `licenseIssueDate`, `religion`, `status`, `birthdate`, `site`, `first_name`, `last_name`, `education`, `employmentType`, `maritalStatus`, `created_at`, `updated_at` ) VALUES ( :id, :phone, :email, :hashedPassword, :gender, :license_type, :national_number, :name_arabic, :name_english, :issue_date, :expiry_date, :license_categories, :address, :card_id, :occupation, :licenseIssueDate, :religion, :status, :birthdate, :site, :first_name, :last_name, :education, :employmentType, :maritalStatus, NOW(), NOW() ) "; $stmt = $con->prepare($sql); if (!$stmt) { throw new Exception("Failed to prepare statement: " . $con->error); } // Bind parameters $paramsToBind = [ 'id', 'phone', 'email', 'hashedPassword', 'gender', 'license_type', 'national_number', 'name_arabic', 'name_english', 'issue_date', 'expiry_date', 'license_categories', 'address', 'card_id', 'occupation', 'licenseIssueDate', 'religion', 'status', 'birthdate', 'site', 'first_name', 'last_name', 'education', 'employmentType', 'maritalStatus' ]; foreach ($paramsToBind as $param) { if (isset($inputData[$param])) { $stmt->bindValue(":$param", $inputData[$param], PDO::PARAM_STR); } else { $stmt->bindValue(":$param", null, PDO::PARAM_STR); } } // Log SQL and parameters for debugging error_log("SQL: " . $sql); error_log("Params: " . print_r($inputData, true)); // Execute the statement if (!$stmt->execute()) { throw new Exception("Failed to execute statement: " . $stmt->errorInfo()[2]); } // Check if the record was successfully saved if ($stmt->rowCount() > 0) { printSuccess($inputData['id']); } else { printFailure("Failed to save driver data"); } } catch (PDOException $e) { error_log("Database error: " . $e->getMessage()); printFailure("A database error occurred: " . $e->getMessage()); } catch (Exception $e) { error_log("An error occurred: " . $e->getMessage()); printFailure("An error occurred: " . $e->getMessage()); }