根据if条件转移操作

时间:2010-11-30 12:16:19

标签: php

提前致谢。我正在非常详细地写这篇文章。所以不要惊慌地看着这条消息的长度。

我有一个名为retrievefieldex11.29.2.56.php的页面。此处需要考虑此问题的字段是ID字段(name = usersubmit)Key(name = key)字段。现在当用户输入他的id(name = usersubmit)并且他没有在我使用这个条件检查的关键字段中输入键值时if (($_SERVER['REQUEST_METHOD'] == 'POST') && ($_POST['key'] == "")) 它应该指向与retrievefieldex11.29.2.56.php相同的页面。为此我正在使用

<form name="retrieve.php" action="retrievefieldex11.29.2.56.php" method="POST">

声明,以便它回发到同一页面并执行操作以从数据库中检索记录并将其打印在同一页面上。

Database code to retrieve rows
Print rows on the same page.

现在,如果用户同时输入了id字段和密钥字段,我将使用此语句来检查条件。

else if (($_SERVER['REQUEST_METHOD'] == 'POST') && ($_POST['key']))

然后应该将页面重定向到另一个页面,在该页面中执行以下操作。

header( 'Location: Decryption.php' ) ;

在Decryption.php页面中,部分代码如下

$userId = $_POST['usersubmit'];

[COLOR =“red”]此值未从上一页获取。[/ COLOR]。我需要从上一页获取此页面

其余的数据库代码,用于从表中检索值。

我的问题是,当我测试用户输入其id而不是关键字段的部分时,正在执行数据库操作。但是,当用户输入他的ID和密钥时,[COLOR =“Red”]我被重定向到Decryption页面,但ID值(name = usersubmit [/ COLOR])没有从上一页转移到Decryption页。请建议我如何解决这个问题?

我希望这是有道理的。如果你一起看整个节目,我的整个问题会更有意义。请帮忙。提前致谢。

总代码

<html>
<head>
</head>

<body>
<form name="retrieve.php" action="retrievefieldex11.29.2.56.php" method="POST">
Enter your ID<input name="usersubmit" type="text"> <br>

<table><tr>
<td><b>Key size in bits: </b></td>

<td><select name="keySize">
<option value="128" selected="selected">128</option>
<option value="192">192</option>
<option value="256">256</option>
</select></td>
</tr>

<tr>
<td><b>Key in hex: </b></td>
<td><input type="text" size="66" name="key"></td></tr>

<tr>
<td><b>Ciphertext in hex: </b></td>
<td><input type="text" size="66" name="ciphertext"></td>

</tr>


</table>
<?php
mysql_connect("localhost","root","");
mysql_select_db("encryption") or die(mysql_error());
$userId = $_POST['usersubmit'];
if (($_SERVER['REQUEST_METHOD'] == 'POST') && ($_POST['key'] == "")) 
{

 $query = mysql_query("select * from employee_details where id = '$userId'");
  if($row=mysql_fetch_assoc($query))
    {
     echo '<tr>';
     foreach($row as $value)
     echo '<td>'.$value.'</td>';
     echo '</tr>';
    }
  else
  echo "No rows returned";
  }
 else if (($_SERVER['REQUEST_METHOD'] == 'POST') && ($_POST['key']))
 {


   header( 'Location: Decryption.php' ) ;

In decryption page

<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
mysql_connect("localhost","root","");
mysql_select_db("encryption") or die(mysql_error());
$userId = $_POST['usersubmit'];
$columname = "ciphertext";
$tablename = "employee_details";

 function getField($field, $tbl_name, $condition)
 {

 $result = mysql_query("SELECT $field FROM $tbl_name WHERE id = ".$condition);
 return @mysql_result($result, 0);
 }

 $myValue = getField($columname,$tablename,$userId);
 echo "$myValue";
 echo "<br>";

?>


 }



?>
<br>
<input name="submit" type="submit" value="Submit"><table>
</table>
</form>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

如果发送位置标头,浏览器会发送该URI的GET请求,并且不会重新提交上次请求中的任何数据。 一种解决方案是将POSTed数据作为GET参数添加到您作为新位置发送的URL。当然,您必须将Decryption.php更改为使用$_GET。 另一个解决方案:不要发送位置标题,只需在脚本中包含Decryption.php。