执行查询后到达标题的php代码
<?php
if (isset($_POST['Submit1'])) {
$con = mysqli_connect("localhost:3306", "root", "", "travels");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$fname1 = $_POST['fname'];
$lname1 = $_POST['lname'];
$pnum1 = $_POST['pnum'];
$email1 = $_POST['email'];
$fcode = $_POST['fcode'];
$sql = "insert into customer_info(fname,lname,pnumber,email) values ('$fname1','$lname1','$pnum1','$email1')";
$sql1 = "insert into booking_info(fname,lname,pnumber,email,f_code) values ('$fname1','$lname1','$pnum1','$email1','$fcode')";
$sql2 = "update flight_info set seats_available=seats_available-1 where flight_code='$fcode'";
mysqli_query($con, $sql);
mysqli_query($con, $sql1);
mysqli_query($con, $sql2);
header("Location: Booking_confirm.php");
}
?>
HTML代码
<div class="container mt-5">
<div class="row">
<div class="col-md-6">
<form action="Booking.php" method="POST">
<div class="form-group">
<label for="fname">First Name: </label>
<input type="text" name="fname" class="form-control" id="fname"/>
</div>
<div class="form-group">
<label for="lname">Last Name: </label>
<input type="text" name="lname" class="form-control" id="lname"/>
</div>
<div class="form-group">
<label for="pnum">Phone Number: </label>
<input type="text" name="pnum" class="form-control" id="pnum"/>
</div>
<div class="form-group">
<label for="email">Email-Address: </label>
<input type="text" name="email" class="form-control" id="email"/>
</div>
<div class="form-group">
<label for="flight">Flight No: </label>
<input type="text" name="fcode" class="form-control" id="fcode"/>
</div>
<form action="Booking_confirm.php" method="POST" target="_blank">
<button type="Submit" name="Submit1" class="btn btn-primary">Book</button>
</form>
</form>
</div>
这是我的代码的样子。由于某种原因,我的标头不起作用,我无法找出原因。 帮助将不胜感激。 我尝试了所有可能的更改以使标头正常工作,但没有用
答案 0 :(得分:1)
您有两个嵌套表单,第一个表单action="Booking.php"
包含所有字段,而第二个嵌套表单action="Booking_confirm.php"
仅包含提交按钮NO
字段。
替换
<form action="Booking_confirm.php" method="POST" target="_blank">
<button type="Submit" name="Submit1" class="btn btn-primary">Book</button>
</form>
与
<button type="Submit" name="Submit1" class="btn btn-primary">Book</button>
点击提交时,没有$_POST['fname']
,$_POST['lname']
等。
编辑:您可能还需要替换
<form action="Booking.php" method="POST">
使用
<form action="Booking_confirm.php" method="POST" target="_blank">
取决于放置“标头” /代码的位置
答案 1 :(得分:0)
确保在header()函数之前没有空格,html标记或任何输出...
上传整个代码,结构,以便我们可以帮助您找到解决方案