我正在尝试制作收件箱系统,并且在编写撰写文件时,出现标题中出现的错误。
我已经读过一个问题,将其放在不同的花括号中是行不通的。
请通过向我发送正确的代码来帮助我。 会很感激的 谢谢!
<?php
// Include config file
require_once "../html/incl/php/db/config.php";
// Define variables and initialize with empty values
$recipient = $subject = $message = "";
$recipient_err = $subject_err = $message_err = "";
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
// Validate recipient
$input_recipient = trim($_POST["recipient"]);
if(empty($input_recipient)){
$recipient_err = "Please enter a recipient.";
} elseif(!filter_var($input_recipient, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^[a-zA-Z\s]+$/")))){
$recipient_err = "Please enter a valid recipient.";
} else{
$recipient = $input_recipient;
}
// Validate subject
$input_subject = trim($_POST["subject"]);
if(empty($input_subject)){
$subject_err = "Please enter a subject.";
} else{
$subject = $input_subject;
}
// Validate message
$input_message = trim($_POST["message"]);
if(empty($input_message)){
$message_err = "Please enter a message.";
} else{
$message = $input_message;
}
// Check input errors before inserting in database
if(empty($recipient_err) && empty($subject_err) && empty($message_err)){
// Prepare an insert statement
$sql = "INSERT INTO messages (recipient, subject, message) VALUES (?, ?, ?)";
if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "sss", $param_recipient, $param_subject, $param_message);
// Set parameters
$param_recipient = $recipient;
$param_subject = $subject;
$param_message = $message;
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Records created successfully. Redirect to landing page
header("location: index.php");
exit();
} else{
echo "Something went wrong. Please try again later.";
}
}
mysqli_stmt_close($stmt);
}
// Close connection
mysqli_close($link);
}
?>
警告:mysqli_stmt_close()期望参数1为mysqli_stmt,布尔值在
中给出