单击提交按钮重定向到index.php

时间:2014-04-03 04:48:34

标签: php redirect

这是我的代码。

if(isset($_POST['add']))
{
  $_POST['os_number'];
  $_POST['product'];
  $_POST['quantity'];
  header('location:index.php?page=pos');
}

此代码属于pos.php并链接(pos/index.php?page=pos)但是当我点击提交按钮时,它会使用此链接(pos/index.php?os_number=1001&product=1&quantity=&add=ADD)重定向到 index.php 我想知道为什么。我需要你的帮助。它应保留在pos/index.php?page=pos链接中。

2 个答案:

答案 0 :(得分:2)

如果您要将表单发布到index.php,可以删除代码并在html上使用此代码。这会在您点击提交时将您重定向到index.php?page=pos

<form action="index.php?page=pos" method="post">
    <input type = "text"    name = "os_number"/> 
    <input type = "text"    name = "product"/> 
    <input type = "text"    name = "quantity"/> 
    <input type = "submit"  name = "add" value = "ADD" /> 
</form>

更好的是,您可以将page=pos放在隐藏的输入

<input type = "hidden"  name = "page" value = "pos"/> 

希望这个帮助

答案 1 :(得分:0)

exit行之后使用header('location:index.php?page=pos');