[英]How to redirect to another page after submit in php
How to redirect to a different page after user clicks Add: I am trying to redirect the user to a different page called (Thank_you.php) after the user fills out the form fields and clicks Add to submit the form. 用户单击添加后如何重定向到另一个页面:在用户填写表单字段并单击添加以提交表单后,我试图将用户重定向到另一个页面(Thank_you.php)。
//include the header
$page_title = 'Add Company';
include ('includes/header.html');
echo '<h1>Add Company</h1>';
require_once ('../mysqli_connect.php');
if ($_POST['submitted']){
$company_name=$_POST['company_name'];
$product_type=$_POST['product_type'];
$city=$_POST['city'];
$state=$_POST['state'];
$query="INSERT INTO Company (Company_Name, Product_Type, City, State)
Values ('$company_name', '$product_type', '$city','$state')";
$result=@mysqli_query ($dbc, $query);
if ($result){
//echo "<center><p><b>Thank you.</b></p>";
echo "<a href=Thank_you.php>The company has been added</a></center>"; // echo "<a href=index.php>Show All URLs</a></center>";
}else {
// echo "<p>The record could not be added due to a system error" . mysqli_error() . "</p>";
}
} // only if submitted by the form
mysqli_close($dbc);
?>
<form action="<? echo $PHP_SELF;?>" method="post"><p>
Company Name:<br> <input name="company_name" size=30><p>
Product Type:<br> <input name="product_type" size=30><p>
City:<br> <input name="city" size=30><p>
State:<br> <input name="state" size=30><p>
<input type=submit value=Add>
<input type=reset value=Clear>
<input type=hidden name=submitted value=true>
</form>
<?
//include the footer
include ("includes/footer.html");
?>
this should work 这应该工作
$page_title = 'Add Company';
include ('includes/header.html');
echo '<h1>Add Company</h1>';
require_once ('../mysqli_connect.php');
if ($_POST['submitted']){
$company_name=$_POST['company_name'];
$product_type=$_POST['product_type'];
$city=$_POST['city'];
$state=$_POST['state'];
$query="INSERT INTO Company (Company_Name, Product_Type, City, State)
Values ('$company_name', '$product_type', '$city','$state')";
$result=@mysqli_query ($dbc, $query);
if ($result){
header("Location: Thank_you.php");
}else {
// echo "<p>The record could not be added due to a system error" . mysqli_error() . "</p>";
}
} // only if submitted by the form
mysqli_close($dbc);
?>
<form action="<? echo $PHP_SELF;?>" method="post"><p>
Company Name:<br> <input name="company_name" size=30><p>
Product Type:<br> <input name="product_type" size=30><p>
City:<br> <input name="city" size=30><p>
State:<br> <input name="state" size=30><p>
<input type=submit value=Add>
<input type=reset value=Clear>
<input type=hidden name=submitted value=true>
</form>
<?
//include the footer
include ("includes/footer.html");
?>
I think header("Location: Thank_you.php"); 我认为header(“ Location:Thank_you.php”); should work . 应该管用 。 Updated code will be : 更新的代码将是:
$ $
page_title = 'Add Company';
include ('includes/header.html');
echo '<h1>Add Company</h1>';
require_once ('../mysqli_connect.php');
if ($_POST['submitted']){
$company_name=$_POST['company_name'];
$product_type=$_POST['product_type'];
$city=$_POST['city'];
$state=$_POST['state'];
$query="INSERT INTO Company (Company_Name, Product_Type, City, State)
Values ('$company_name', '$product_type', '$city','$state')";
$result=@mysqli_query ($dbc, $query);
if ($result){
header("Location: Thank_you.php");
}else {
// echo "<p>The record could not be added due to a system error" . mysqli_error() . "</p>";
}
} // only if submitted by the form
mysqli_close($dbc);
?>
<form action="<? echo $PHP_SELF;?>" method="post"><p>
Company Name:<br> <input name="company_name" size=30><p>
Product Type:<br> <input name="product_type" size=30><p>
City:<br> <input name="city" size=30><p>
State:<br> <input name="state" size=30><p>
<input type=submit value=Add>
<input type=reset value=Clear>
<input type=hidden name=submitted value=true>
</form>
<?
//include the footer
include ("includes/footer.html");
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.