Hi all,

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']; 

This value is not being fetched from the previous page. 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.

<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>

Recommended Answers

All 2 Replies

When you redirect, you will need to pass the variable as part of the re-direct.

header("Location: Decryption.php?name=".urlencode($usersubmit));

Next time you post something, please use code (

...

) tags around the code that you are including in the post.

When you redirect, you will need to pass the variable as part of the re-direct.

header("Location: Decryption.php?name=".urlencode($usersubmit));

Next time you post something, please use code (

...

) tags around the code that you are including in the post.

Hi,

Thanks for your reply chris.

When I include that in the first page,

header("Location: Decryption.php?name=".urlencode($usersubmit));

is this what I should include in the second page?

$userId = $_POST['usersubmit'];

& Thanks for the tip on code tags. dint know about that until you mentioned it to me.. Kinda new to posting in forums and all. Appreciate your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.