duanfei9278 2014-04-18 23:28
浏览 81

发现PHP Header 302

I am trying to go back to the page i came from after the update is submitted. the $pagefrom gets populated from the page before. that works fine. I get redirected to a page that says 302 found but its the same url as my current page.

<?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();
}
?>

I think something is wrong with header('Location: '.$pagefrom); but everything i try i still can not get it to reload the page before.

  • 写回答

2条回答 默认 最新

  • droxlzcgnr639823 2014-04-18 23:35
    关注

    Try adding die(); the next line you use Header('Location: ....'); - if you don't the php will continue working further. Also you probably want to use the form in the page the source code is from. Here you dont provide the pagename anymore therefore when you use form from this page - the $pagefrom is empty and redirection goes to current page. Try adding it as hidden input for this form, and it should work.

    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line