I am trying to pass a form input through an encryption script into a database.

I cannot seem to pass the "data" info from the form to the script.

Static variables work fine...

<td><label>Data:</label> <input type="password" name="data" value="" size="10">
<?php

   $key = "xxxxxx";
   $input = data;

   $td = mcrypt_module_open('tripledes', '', 'ecb', '');
   $iv = "11111111";
   mcrypt_generic_init($td, $key, $iv);
   $output = mcrypt_generic($td, $input);
   mcrypt_generic_deinit($td);
   mcrypt_module_close($td);
?> 

Thank you for your time...

Cheers,
truman

    You would access the data input through the superglobal $_POST["data"]

      I tried to retrieve the variable using a superglobal, but when the information is spit back the information is blank... Static variables work beautifully, but I need the user's input...

      Is it possible to pull that variable if everything takes place on the same page??? Because I thought that in order for a superglobal to work one would have to post the info to another page and then retrieve the variable...

      thank you,
      truman

        Can you change the line where you set $input, to:-

        $input = $_POST['data']; 
        

        That should work (presuming your form submits using POST method) but from what you are saying, it doesn't, so add this line after that:-

        die($input); 
        

        After submitting your form, do you get the 'data' you expected displayed on screen? Just trying to work out where your problem lies...

          The form does use a POST method... I still get the same result... I am truly perplexed because I've tried everything I could think of (even off the wall stuff)...

          Here is a larger chunk of the code (the whole form is huge)

          <form action="<?php echo $editFormAction; ?>" method="post" name="form1">
                      <h2>Applicant Data</h2>
          			<h3>Applying for the position of <?php echo $row_openPos['position_Title']; ?> <input name="applicant_PosApplied" type="hidden" value="<?php echo $row_openPos['position_Title']; ?>" /></h3>
                      <table class="tblAPPDATA" width="100%" cellpadding="2" cellspacing="2">
                                     <tr> 
          
                      <td><label>DATA:</label> <input type="password" name="data" value="" size="10">
          <?php
          
             $key = "xxxxxx";
             $input = $_POST['data']; 
          
             $td = mcrypt_module_open('tripledes', '', 'ecb', '');
             $iv = "11111111";
             mcrypt_generic_init($td, $key, $iv);
             $output = mcrypt_generic($td, $input);
             mcrypt_generic_deinit($td);
             mcrypt_module_close($td);
          ?> 
          <input name="ouput_data" type="hidden" value="<?php echo "$output" ?>" /> 

          I really appreciate all the help...

          Cheers,
          truman

            I think we need to make sure the basics are working as expected.

            The script that handles your POST request - can you put these 2 lines at the top of that script temporarily, fill your form in, submit it and post the exact output here?

            print_r($_POST);
            exit;
            

            If we see the expected output, at least we know your form is ok, etc.

              The post command posts to a command to INSERT into a database on the same page... I assume that's why I cannot retrieve the variable using standard super globals...

              I added the print command and I received

              Array ()

              Since the form and the script reside on the same page I was not able to fill out the form... It read the print command first...

              I may be trying to accomplish something that cannot be accomplished...

              Thank you again,
              truman

                The print command stops the rest of the form past its location in the document code... It doesn't render the rest of the page... However it prints out

                Array ()

                Since the form is posting to an action within the same page... Could that be the reason the super globals are not working???

                  Yep. Change this in your HTML:

                  <form action="<?PHP echo $editFormAction; ?>" method="post" name="form1">

                  to this:

                  <form action="<?PHP echo $editFormAction; ?>?submit=true" method="post" name="form1">

                  Then, change the two lines suggested above to this:

                  if(!empty($_GET['submit']) || !empty($HTTP_GET_VARS['submit'])) {
                  print_r($_POST); 
                  exit;
                  }

                    OK... the print command gave me some insight... The form is picking up everything that it is suppose to, but it is not inserting the variable into the form...

                    It is encrypting blank space...

                    But on the bright side at least I can see the variable from the $_POST

                      Okay, go ahead and get rid of those debug lines (and change the HTML code back), and repost your entire code again. Not snippets, the whole thing.

                      I'm wondering if it's not trying to do the encrypting before the form's submitted (i.e. on the first load of the script).

                        You don't have to post to another page for a post to work.

                        You can do

                        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" metho="post">

                        <input type="submit" name="submit" value="Submit" />

                        Then at the top of the page you can check...

                        if($_POST["submit"])
                        {
                        do stuff
                        }

                          I tried to cut as much as I could, but I could not get it under 10,000 chars...

                            Yeah... over 100,000 chars... Ok... thus far I can tell that it does recognize the POST variable "data"... It will encrypt static variables... But it will not insert the POST variable into the encryption script...

                              May be a stupid question but anyway : have you check that you have a " </form> " HTML tag
                              at the end of your form ?

                                Yep... It's there...

                                Is there any way to establish the variable from the value of the input and not it's value after POST

                                Something like this <input name="data" value="<? = $data ?>">

                                At this point my I am grasping for straws...

                                  This was the "old way" to get the content of HTML form. You had global variables
                                  with the content. But it was dangerous (from a security point of view) so it was discarded
                                  in profit of $REQUEST, $GET, $POST, etc.

                                  May be you should try with a very simple HTML form, calling the same PHP script
                                  and print the value in $_POST variables ?

                                  Something like this :

                                  <form method="post" action="myscript.php">
                                  <input type="password" name="data" value="" size="10">
                                  <input type="submit" value="ok">
                                  </form>

                                  and myscript.php :

                                  <?PHP

                                  print "value = ###".$_POST["data"]."###<br>\n";

                                  ?>

                                  To see if it's ok that (simple) way, and then add progressively the rest ?

                                    Thank you guys for all of your help... I found a work around that will do the job...

                                    Cheers,
                                    truman

                                      23 days later

                                      Well what's the work around?

                                        Write a Reply...