Thanks in advance. I am writing this in great detail. So dont panic looking at the length of this message.
I have a page called retrievefieldex11.29.2.56.php. Fields that need to be considered for this problem here is the ID field (name = usersubmit) the Key(name = key) field. Now when the user enters his id( name = usersubmit) and if he does not enter the key value in the key field which I am checking by using this condition if (($_SERVER['REQUEST_METHOD'] == 'POST') && ($_POST['key'] == ""))
It should be directed to the same page that is retrievefieldex11.29.2.56.php. And for this I am using the
<form name="retrieve.php" action="retrievefieldex11.29.2.56.php" method="POST">
Statement so that it postbacks to the same page and performs operations to retrieve records from the database and print it on the same page.
Database code to retrieve rows
Print rows on the same page.
Now if the user enters into both id fields and the key field, I am using this statement for checking the condition.
else if (($_SERVER['REQUEST_METHOD'] == 'POST') && ($_POST['key']))
then the page should be redirected to another page where in the following operation is carried out.
header( 'Location: Decryption.php' ) ;
In the Decryption.php page part of the code is as follows
$userId = $_POST['usersubmit'];
[COLOR="red"]This value is not being fetched from the previous page.[/COLOR]. I need this page to be fetched from the previous page
Rest of the Database code to retrieve values from the table.
My problem is that when I am testing for the part where the user enters his id but not the key field the database operations are being performed. However when the user enters his id and the key, [COLOR="Red"]I am being redirected to the Decryption page but the ID value ( name = usersubmit [/COLOR]) is not being transferred from the previous page to the Decryption page. Please suggest me how do I deal this?
I hope that made sense. My whole problem would make further sense if you look at this whole program together. Please help. Thanks in advance.
Total code
<html>
<head>
&l开发者_运维知识库t;/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>
If you send a location header, the browser sends a GET request for that URI and it does not resubmit any data from the last request.
One solution could be to add the POSTed data as GET parameters to the URL you send as new location. Of course you must change Decryption.php to use $_GET
then.
Another solution: Instead of sending a location header, just include Decryption.php right there in your script.
精彩评论