发现PHP Header 302

时间:2014-04-18 23:28:01

标签: php html

我正在尝试返回提交更新后我来自的页面。 $ pagefrom从之前的页面填充。工作正常。我被重定向到一个页面,该页面显示302找到但与我当前页面的URL相同。

<?php
{
$pagefrom=  $_POST['pagename'];

echo $pagefrom;

if(isset($_POST['add']))
{



$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}

if(! get_magic_quotes_gpc() )
{
   $Reg_F_Name = addslashes ($_POST['Reg_F_Name']);
   $Reg_L_Name = addslashes ($_POST['Reg_L_Name']);
}
else
{
   $Req_F_Name = $_POST["Req_F_Name"]; 
   $Reg_L_Name = $_POST["Reg_L_Name"];
}
$Req_ID = $_POST["Req_ID"]; 
$Req_F_Name = $_POST["Req_F_Name"]; 
$Reg_L_Name = $_POST["Reg_L_Name"];
$Reg_Email = $_POST["Reg_Email"];
$Reg_Mod_Request = $_POST["Reg_Mod_Request"];
$Reg_Address_1 = $_POST["Reg_Address_1"];
$Reg_Address_2 = $_POST["Reg_Address_2"];
$Reg_City = $_POST["Reg_City"];
$Reg_State = $_POST["Reg_State"];
$Reg_Zip_Code= $_POST["Reg_Zip_Code"];
$Reg_ID= $_POST["Reg_ID"];
$Reg_Phone = $_POST["Reg_Phone"];
$Reg_Phone= str_replace("-","","$Reg_Phone");
$Reg_Approval_Status= $_POST["Reg_Approval_Status"];
$Reg_Status= $_POST["Reg_Status"];

$sql= "UPDATE $dbtable SET
 Reg_F_Name = '$Reg_F_Name',
 Reg_L_Name = '$Reg_L_Name',
 Reg_Phone = '$Reg_Phone',
 Reg_Email = '$Reg_Email',
 Reg_Mod_Request = '$Reg_Mod_Request',
 Reg_Address_1 = '$Reg_Address_1',
 Reg_Address_2 = '$Reg_Address_2',
 Reg_City = '$Reg_City',
 Reg_State = '$Reg_State',
 Reg_Zip_Code = '$Reg_Zip_Code',
 Reg_Approval_Status='$Reg_Approval_Status',
 Reg_Status='$Reg_Status' 
WHERE Reg_ID = '$Reg_ID'";

mysql_select_db($database);
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not enter data: ' . mysql_error());
}

mysql_close($conn);
header('Location: '.$pagefrom);
}
else
{
?>

<?php
$con=mysqli_connect($dbhost, $dbuser, $dbpass, $database);
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
$query = mysqli_query($con, "SELECT * FROM $dbtable WHERE Reg_ID = '$Reg_ID'");
?>




<form method="post" action="" style="width: 500px">
<fieldset>
<p style="text-align: center">Update A Prayer Request</p>
<div style="width: 500px; float: left">

<?php
while($rows = mysqli_fetch_array($query))
  {

?>
<input type="hidden" name="Reg_ID" value="<?=$rows['Reg_ID']?>">
Please pray for:
<br />First Name: <input name="Reg_F_Name" type="text" id="Reg_F_Name" value="<? echo $rows['Reg_F_Name']; ?>">
<br />Last Name: <input name="Reg_L_Name" type="text" id="Reg_L_Name" value="<? echo $rows['Reg_L_Name']; ?>">
<br />Original Prayer Request: 
<br/><? echo $rows['Reg_Request']; ?>
<br />Update Prayer Request:
<br /><textarea name="Reg_Mod_Request" type="varchar" id="Reg_Mod_Request" rows="5" cols="30"><? echo $rows['Reg_Mod_Request']; ?></textarea>
<br />Primary Address: <input name="Reg_Address_1" type="varchar" id="Reg_Address_1" value="<? echo $rows['Reg_Address_1']; ?>">
<br />Secondary Address:<input name="Reg_Address_2" type="varchar" id="Reg_Address_2" value="<? echo $rows['Reg_Address_2']; ?>">
<br />City:<input name="Reg_City" type="char" id="Reg_City" value="<? echo $rows['Reg_City']; ?>">
<br />State:<input name="Reg_State" type="char" id="Reg_State" value="<? echo $rows['Reg_State']; ?>">
<br />Zip:<input name="Reg_Zip_Code" type="char" id="Reg_Zip_Code" value="<? echo $rows['Reg_Zip_Code']; ?>">
<br />Phone Number (555-555-5555):<input name="Reg_Phone" type="char" id="Reg_Phone" value="<? echo $rows['Reg_Phone']; ?>">
<br />Email Address:<input name="Reg_Email" type="varchar" id="Reg_Email" value="<? echo $rows['Reg_Email']; ?>">
<br />Approval Status: <select id="Approval" name="Approval">
            <!--Call run() function-->
            <option value="0" <?php echo $rows['Reg_Approval_Status'] == "0" ?  "selected" : '' ?>>Waiting Approval</option>
            <option value="1" <?php echo $rows['Reg_Approval_Status'] == "1" ?  "selected" : '' ?>>Accept</option>
            <option value="2" <?php echo $rows['Reg_Approval_Status'] == "2" ?  "selected" : '' ?>>Decline</option>
            </select>               
<br />Enabled Request: <select id="Activate" name="Activate">  
            <option value="0" <?php echo $rows['Reg_Status'] == "0" ?  "selected" : '' ?>>Disable</option>
            <option value="1" <?php echo $rows['Reg_Status'] == "1" ?  "selected" : '' ?>>Enable</option>
            </select> 
</div>
<input name="add" type="submit" id="add" value="Update Prayer Request">
</fieldset>
</form>

<?php
}
}
mysql_close();
}
?>

我觉得有些不对劲     标题('Location:'。$ pagefrom); 但我尝试的一切我仍然无法让它重新加载页面之前。

2 个答案:

答案 0 :(得分:1)

删除echo $ pagefrom;从脚本顶部或移动它上面的标题行。输出开始后,无法发送标题。

请参阅:header

答案 1 :(得分:0)

尝试添加die();您使用的下一行Header('Location: ....'); - 如果您不这样做,php将继续进一步工作。 您也可能希望使用源代码所在页面中的表单。因此,当您使用此页面中的表单时,您不再提供pagename - $pagefrom为空,重定向将转到当前页面。 尝试将其添加为此表单的隐藏输入,它应该可以正常工作。