我有一个PHP表单,它将一些数据提交给数据库。表单操作代码如下:
<form action="<?php echo $editFormAction; ?>"
method="post" name="form1" id="form1">
$ editFormAction引用以下代码块:
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO gifts (giftid, customerid, itemtype, itemtitle, itemdescription, itemurl, dateadded, received, datereceived, vendor, ordernumber) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['giftid'], "int"),
GetSQLValueString($_POST['customerid'], "int"),
GetSQLValueString($_POST['itemtype'], "text"),
GetSQLValueString($_POST['itemtitle'], "text"),
GetSQLValueString($_POST['itemdescription'], "text"),
GetSQLValueString($_POST['itemurl'], "text"),
GetSQLValueString($_POST['dateadded'], "date"),
GetSQLValueString($_POST['received'], "text"),
GetSQLValueString($_POST['datereceived'], "date"),
GetSQLValueString($_POST['vendor'], "text"),
GetSQLValueString($_POST['ordernumber'], "text"));
mysql_select_db($database_testing_registryconnection, $testing_registryconnection);
$Result1 = mysql_query($insertSQL, $testing_registryconnection) or die(mysql_error());
$insertGoTo = "success.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
我在许多其他页面中使用了此代码的变体,但对于此特定项目,虽然表单数据确实已插入MySQL数据库,但表单页面只是重新加载以显示空白表单。如果我没记错的话,这个确切的代码在这个项目上应该有一段时间了,但是必须改变一些干扰重定向到'success.php'的东西。
我应该检查的任何提示?你需要看更多代码吗?
答案 0 :(得分:0)
结合我上面的两条评论......我首先尝试用绝对值(即http://www.mydomain.com/success.php)替换$insertGoTo
,然后替换最后一行(为了清理它) up)with:header("Location: $insertGoTo");
。看看是否有效?