【问题标题】:How to redirect after form submit using post method (Post/Redirect/Get) with PHP如何使用 PHP 的 post 方法(Post/Redirect/Get)在表单提交后重定向
【发布时间】:2013-03-29 12:23:47
【问题描述】:

我有以下表格:

<form id="frmAeroportonew" name="frmAeroportonew" method="post" action="<?php echo $editFormAction; ?>">
<table>      
  <tr>
    <td><input name="iata" type="text" id="iata" value="" /></td>
    <td><input name="icao" type="text" id="icao" value="" /></td>
    <td><input name="cidade" type="text" id="cidade" value="" /></td>
    <td><input name="pais" type="text" id="pais" value="" /></td>
    <td><input name="destino" type="checkbox" id="destino" value="" /></td>
    <td><input name="alternativo" type="checkbox" id="alternativo" value="" /></td>
    <td><input name="h24" type="checkbox" id="h24" value="" /></td>
    <td><input name="btnaeroportonew" id="btnaeroportonew" type="submit" value="+" /></td>
  </tr>
</table>
<input type="hidden" name="MM_insert" value="frmAeroportonew">

这个想法是提交这个表单,而不是重定向到另一个页面 (teste_redirect.php) 将输入 (id=iata) 值附加到 url (teste_redirect.php?iata=input_value)。

PHP代码是用dreamweaver cs6制作的:

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "frmAeroportonew")) {
  $insertSQL = sprintf("INSERT INTO tblaeroportos (iata, icao, cidade, pais, destino, alternativo, H24) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                   GetSQLValueString($_POST['iata'], "text"),
                   GetSQLValueString($_POST['icao'], "text"),
                   GetSQLValueString($_POST['cidade'], "text"),
                   GetSQLValueString($_POST['pais'], "text"),
                   GetSQLValueString(isset($_POST['destino']) ? "true" : "", "defined","1","0"),
                   GetSQLValueString(isset($_POST['alternativo']) ? "true" : "", "defined","1","0"),
                   GetSQLValueString(isset($_POST['h24']) ? "true" : "", "defined","1","0"));

  mysql_select_db($database_connect, $connect);
  $Result1 = mysql_query($insertSQL, $connect) or die(mysql_error());

  $insertGoTo = "teste_redirect.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

感谢您的所有帮助。谢谢你

【问题讨论】:

  • 好的,想法是这样,但问题是什么?

标签: php redirect post get


【解决方案1】:

将您的 insertGoto 更改为

$insertGoTo = "teste_redirect.php?iata=".$_POST['iata'];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-10
    • 2010-10-10
    • 1970-01-01
    • 2015-08-28
    • 2017-01-12
    • 2022-07-10
    相关资源
    最近更新 更多