3
我有一些不需要的字段。在數據庫中,這些字段被設置爲Null:YES。 如果某個字段爲空,則下面的代碼將引發錯誤。請你幫助避免這種情況的最佳等待時間,我唯一想到的解決方案是將變量設置爲「'如果爲空()」。Mysqli插入語句 - 空值
$query = "INSERT INTO gifts
(dateRequest, firstName, lastName, note, lastUpdated)
VALUES
(?, ?, ?, ?, NOW())";
if($stmt = $dbc->prepare($query)) {
$dateRequest = $_POST['dateRequest'];
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$note = $_POST['note'];
$stmt->bind_param('ssss', $dateRequest, $firstName, $lastName, $note);
if($stmt->execute()) {
$stmt->close();
header('Location: index.php');
}
else {
echo $stmt->error;
}
}