Php 在表单发布后重定向到URL

Php 在表单发布后重定向到URL,php,forms,url,post,redirect,Php,Forms,Url,Post,Redirect,我有一个无法解决的问题。我想在发布表单后重定向到URL(单击按钮)。我该怎么做?到目前为止,我还没有在互联网上找到解决方案 我的文件: addmatch.html <html> <body> <form action="insert.php" method="post"> Date: <input type="text" name="date"> Home: <input type="text" name="home"> Away: &

我有一个无法解决的问题。我想在发布表单后重定向到URL(单击按钮)。我该怎么做?到目前为止,我还没有在互联网上找到解决方案

我的文件:

addmatch.html

<html>
<body>
<form action="insert.php" method="post">
Date: <input type="text" name="date">
Home: <input type="text" name="home">
Away: <input type="text" name="away">
Result: <input type="text" name="result">
<input type="submit" name="submit">
</form>

</body>
</html>

日期:
主页:
离开:
结果:
insert.php

<?php

define("HOST", "localhost");
define("DBUSER", "..");
define("PASS", "..");
define("DB", "..");

$con=mysqli_connect(HOST, DBUSER, PASS, DB);

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$sql="INSERT INTO wedstrijden (date, home, away, result)
VALUES
('$_POST[date]','$_POST[home]','$_POST[away]','$_POST[result]')";

if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error($con));
  }
echo "1 record added";

mysqli_close($con);
?>

正如我现在看到的,您的表单将向insert.php发送post请求
若要在数据库中保存数据后重定向用户,应添加标题(“location youUrl.php”);在任何输出(回显、打印等)之前

使用标题(“位置:ur_路径”);人们使用javascript来实现这一点。使用诸如
window.location.assign(“你的url在这里”)
@zander这取决于具体情况,有时候PHP可能更合适。也就是说,Javascript可以被禁用。哦,那么header(..)应该是doDanger:您很容易受到您需要对抗的攻击。