我正在尝试重定向到同一页面,并在php中提交表单后显示成功消息。当您提交表单时,用户被带到registration_detail
,没有消息已发送该表单。我尝试了各种方法。我做不到请帮助我。
<?php
require_once "conn.php";
// $reg_id1 = intval($_POST['reg_id']);
$posted = false;
$registration_date = $building_use_id = $building_category =$reg_id="";
if($_SERVER["REQUEST_METHOD"] == "POST"){
$posted = true;
$reg_id=intval($_POST['reg_id']);
$registration_date = trim($_POST["registration_date"]);
$building_use_id = trim($_POST["building_use_id"]);
$building_category = trim($_POST["building_category"]);
$sql = "INSERT INTO bps_registration_application (registration_date, building_use_id, building_category,reg_id) VALUES (?, ?, ?, ?)";
if($stmt = mysqli_prepare($conn, $sql)){
mysqli_stmt_bind_param($stmt, "ssss",$registration_date, $building_use_id, $building_category,$reg_id);
$reg_id=intval($_POST['reg_id']);
$registration_date=$registration_date;
$building_use_id = $building_use_id;
$building_category = $building_category;
if(mysqli_stmt_execute($stmt)){
if(!empty($reg_id)){
$success = "Message successfully sent";
echo "<script type='text/javascript'>alert('submitted successfully!')</script>";
header("location: registration_detail.php?id=".$reg_id);
exit();
}
else
{
header("location: registration_detail.php");
exit();
}
}
else{
echo "Something went wrong. Please try again later.";
}
}
echo $success;
mysqli_close($conn);
}
?>