我正在尝试将表单中的数据添加到数据库中。但是,当我单击“提交”按钮时,它会显示以下错误:
Notice: Array to string conversion in C:\xampp\htdocs\stock\php_action\createAppointment.php on line 16
Notice: Array to string conversion in C:\xampp\htdocs\stock\php_action\createAppointment.php on line 16
{"success":true,"messages":"Successfully Added"}
我已经搜索并登陆了这个网站。它告诉我使用implode,但我不知道放在哪里,当我查看函数时,它将数组回显到字符串中,但我想将数据添加到数据库而不是回显它。
以下是第16行事项的代码:
<?php
require_once 'core.php';
$valid['success'] = array('success' => false, 'messages' => array(), 'appointment_id' => '');
// print_r($valid);
if($_POST) {
$appointmentDate = date('Y-m-d', strtotime($_POST['appointmentDate']));
$patientName = $_POST['patientName'];
$physicianName = $_POST['physicianName'];
$description = $_POST['description'];
$sql = "INSERT INTO appointment (appointment_date, patient_name, physician_name, description) VALUES ('$appointmentDate', '$patientName', '$physicianName', '$description')";
}
if($connect->query($sql) === TRUE) {
$valid['success'] = true;
$valid['messages'] = "Successfully Added";
} else {
$valid['success'] = false;
$valid['messages'] = "Error while adding the members";
}
// /if $_POST
// echo json_encode($valid);
$connect->close();
echo json_encode($valid);
// /if $_POST
第16行就是这一行:
$sql = "INSERT INTO appointment (appointment_date, patient_name, physician_name, description) VALUES ('$appointmentDate', '$patientName', '$physicianName', '$description')";
编辑:
我已经检查了我的数据库并且它增加了值(虽然我添加了空数据,除了描述中有's'的顶部数据)但医生姓名和患者姓名是数组。
这是我的医生姓名代码(与患者姓名相同):
<?php
$physicianSql = "SELECT * FROM physician WHERE physician_active = 1 AND physician_status = 1";
$physicianData = $connect->query($physicianSql);
while($row = $physicianData->fetch_array()) {
$selected = "";
if($row['physician_id'] == $orderItemData['physician_id']) {
$selected = "selected";
} else {
$selected = "";
}
echo "<option value='".$row['physician_id']."' id='changePhysician".$row['physician_id']."' ".$selected." >".$row['physician_name']."</option>";
} // /while
?>
这是DB的截图: https://i.imgur.com/PYbUn1G.png