Я получаю следующее сообщение об ошибке:
Предупреждение: отсутствует аргумент 3 для DB :: update (), вызванный в C: \ xampp \ htdocs \ my.sleeptrak.com \ users \ step-1-edit. php в строке 51 и определено в C: \ xampp \ htdocs \ my.sleeptrak.com \ users \ classes \ DB. php в строке 261
Вот моя база данных. php:
public function update($table, $id, $fields){
$sql = "UPDATE {$table} SET " . (empty($fields) ? "" : "`") . implode("` = ? , `", array_keys($fields)) . (empty($fields) ? "" : "` = ? ");
$is_ok = true;
if (!is_array($id)) {
$sql .= "WHERE id = ?";
$fields[] = $id;
} else {
if (empty($id))
return false;
if ($where_text = $this->_calcWhere($id, $fields, "and", $is_ok))
$sql .= "WHERE $where_text";
}
if ($is_ok)
if (!$this->query($sql, $fields)->error())
return true;
return false;
}
А вот моя редакция. php
<form class="needs-validation" method="post">
<div class="offset-2 col-md-8 order-md-1">
<div class="card">
<div class="card-body">
<?php
if(isset($_POST['save'])) {
$fields = array(
"PatientFirstName" => $_POST['PatientFirstName'],
"PatientLastName" => $_POST['PatientLastName'],
"PatientStreet" => $_POST['PatientStreet'],
"PatientCity" => $_POST['PatientCity'],
"PatientProvince" => $_POST['PatientProvince'],
"PatientPostalCode" => $_POST['PatientPostalCode'],
"PatientCountry" => $_POST['PatientCountry'],
"PatientEmail" => $_POST['PatientEmail'],
"PatientPhone" => $_POST['PatientPhone'],
"PatientDOB" => $_POST['PatientDOB'],
"PatientBMI" => $_POST['PatientBMI'],
"PhysicianName" => $_POST['PhysicianName'],
"PhysicianEmail" => $_POST['PhysicianEmail']
);
$db->update("patients", $fields);
//print_r($db->errorInfo());
echo '<div class="alert alert-success mb-4" role="alert">The patient has been successfully updated!</div>';
} else {
?>
<h4 class="mb-3">Edit Patient <?php echo $PatientFirstName . ' ' . $PatientLastName; ?></h4>
<div class="row">
<div class="col-md-6 mb-3">
<label for="PatientFirstName">Patient first name</label>
<input type="text" class="form-control" name="PatientFirstName" value="<?php echo $PatientFirstName; ?>">
<div class="invalid-feedback">Valid first name is required.</div>
</div>
<div class="col-md-6 mb-3">
<label for="PatientLastName">Patient last name</label>
<input type="text" class="form-control" name="PatientLastName" value="<?php echo $PatientLastName; ?>">
<div class="invalid-feedback">Valid last name is required.</div>
</div>
</div>
<div class="row">
<div class="col-md-4 mb-3">
<label for="PatientDOB">Patient DOB</label>
<input type="date" class="form-control" name="PatientDOB" value="<?php echo $PatientDOB; ?>">
</div>
<div class="col-md-4 mb-3">
<label for="email">Email</label>
<input type="text" class="form-control" name="PatientEmail" value="<?php echo $PatientFirstName; ?>">
</div>
<div class="col-md-4 mb-3">
<label for="PatientPhone">Phone</label>
<input type="text" class="form-control" name="PatientPhone" value="<?php echo $PatientPhone; ?>">
<div class="invalid-feedback">Valid last name is required.</div>
</div>
</div>
</div><!--card-body-->
</div><!--card-->
<div class="card mt-3">
<div class="card-body">
<h4>Patient Address</h4>
<div class="row">
<div class="col-md-8 mb-3">
<label for="PatientStreet">Street</label>
<input type="text" class="form-control" name="PatientStreet" value="<?php echo $PatientStreet; ?>">
<div class="invalid-feedback">Valid address is required.</div>
</div>
<div class="col-md-4 mb-3">
<label for="PatientCity">City</label>
<input type="text" class="form-control" name="PatientCity" value="<?php echo $PatientCity; ?>">
<div class="invalid-feedback">
City is required.
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 mb-3">
<label for="state">Province / State</label>
<input type="text" class="form-control" name="PatientProvince" value="<?php echo $PatientProvince; ?>">
<div class="invalid-feedback">
Please provide a valid province/state.
</div>
</div>
<div class="col-md-3 mb-3">
<label for="PatientPostalCode">Postal Code / Zip</label>
<input type="text" class="form-control" name="PatientPostalCode" value="<?php echo $PatientPostalCode; ?>">
<div class="invalid-feedback">
Postal Code / Zip Code is required.
</div>
</div>
<div class="col-md-5 mb-3">
<label for="PatientCountry">Country</label>
<input type="text" class="form-control" name="PatientCountry" value="<?php echo $PatientCountry; ?>">
<div class="invalid-feedback">
Please select a valid country.
</div>
</div>
</div>
</div><!--card-body-->
</div><!--card-->
<div class="card mt-3">
<div class="card-body">
<h4>Body Mass Index</h4>
<div class="row">
<div class="col-md-6 mb-3">
<label for="PatientBMI">Patient BMI</label>
<input type="text" class="form-control" name="PatientBMI" value="<?php echo $PatientBMI; ?>">
</div>
</div>
</div><!--card-body-->
</div><!--card-->
<div class="card mt-3">
<div class="card-body">
<div class="row">
<div class="col-md-6 mb-3">
<label for="PhysicianName">Physician Name</label>
<input type="text" class="form-control" name="PhysicianName" value="<?php echo $PhysicianName; ?>">
<div class="invalid-feedback">Valid last name is required.</div>
</div>
<div class="col-md-6 mb-3">
<label for="PhysicianEmail">Physician Email</label>
<input type="text" class="form-control" name="PhysicianEmail" value="<?php echo $PhysicianEmail; ?>">
</div>
</div>
</div><!--card-body-->
</div><!--card-->
<button class="btn btn-primary btn-lg btn-block mt-4" name="save" type="submit">Update</button>
</div>
</form>
Я исследую все те же ошибки в этой форме, но я не могу это исправить. Я пытался заменить это: php public function update($table, $id, $field)
этим public function update($table, $id, $fields=null)
, но у меня не работает. Как бы то ни было, ошибка исчезла, когда я добавил в функцию значение null, но все еще не сохранял свои изменения в БД