保存并移动到下一页的 HTML 按钮


HTML Button that saves and move to the next page

我有一个小问题。我想在我的 html 页面中有一个按钮,用于保存文本字段中添加的每个数据,以及当我单击它移动到下一页时

我的代码如下...

<input type=button onClick="location.href='education.php'" value='Next'>

但它只会移动到下一页,它不会将数据保存在数据库中......

你能帮我吗?谢谢。

  1. 删除 JavaScript
  2. type更改为submit
  3. <form>包裹
  4. 将窗体的action设置为education.php
  5. 将窗体的method设置为post

然后,在 education.php 中,从$_POST读取数据并使用 PDO(带有绑定变量)将其插入到数据库中。

试试这个:

<?php
if(isset($_POST['submit']))
{
// Insert Query Put here
header('Location: education.php');
}
?>
    <html>
    <head>
    </head>
    <body>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <input type="submit" value="Next" name="submit">
    </form>
    </body>
    </html>

教育.php

   <?php
   echo "Successfully Updated.";
?>

您必须为表单设置如下所示的操作,因为您没有提交表单,而只是重定向到另一个页面而不获取表单数据。

<form action="education.php" method="post">
   <!-- All your input fields here -->
   <input type="submit" name="submit" value="Next">
</form>

而你的教育.php应该是这样的:

<?php
//Get all parameters using $_POST
//Make A connection to database
//Choose a database in which you have to save the data
//Create a SQL query
// run query using mysql_query($query);
//Redirect to anywhere with header("Location:page.php");
?>