我收到以下错误消息:
警告:缺少 DB::update(( 的参数 3,在第 51 行的 C:\xampp\htdocs\my.sleeptrak.com\users\step-1-edit.php 中调用,并在第 261 行的 C:\xampp\htdocs\my.sleeptrak.com\users\classes\DB.php 中定义
这是我的数据库.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 但仍然没有将我的更改保存在数据库中时,错误就消失了。
你必须为更新方法编写所有参数
$db->update("patients", $id, $fields);
你错过了$id。