用户单击“添加”后如何重定向到其他页面:在用户填写表单字段并单击“添加”以提交表单后,我尝试将用户重定向到名为(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");
?>
答案 0 :(得分:0)
这应该有效
$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");
?>
答案 1 :(得分:0)
我认为标题(“位置:Thank_you.php”);应该管用 。更新的代码将是:
$
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");
?>