We help IT Professionals succeed at work.

Form Data is Empty but then Populated on Refresh

Igiwwa
Igiwwa asked
on
290 Views
Last Modified: 2007-12-19
I have a php script which submits a form via POST to another php script.  The second script takes all the data from the first page in the $_POST array and inserts to a mySQL database.  However, when I submit the first form, all the variables in the post array are null, even though they definitely should have values from the other page.  The kicker is that when I refresh the second page or hit the back button and resubmit, suddenly all the variables are populated with my selections and everything works fine.  It almost never works the first time, but almost always works thereafter.  However, when I close my browser and come back in, the problem is there again. Help!
Comment
Watch Question

Commented:
Post some of your code - a condensed version at least.

Commented:
change your browser cache settings or try another browser .... or at least post some code
gr8gonzoConsultant
CERTIFIED EXPERT

Commented:
Another test would be to create a test page that does nothing but print out the contents of $_POST. Then have the first form post to that test page instead. See if the test page picks up the values correctly - then go back and change the values and post again and see if everything is still good. Do this 3-4 times and if everything works, it's probably a code problem and not a cache problem.

Otherwise, if (when you post the 2nd time with different values) the test page shows you old values, then it's most definitely a cache issue, and you may want to look into setting the session_cache_limiter to none (I think that's right - look up session_cache_limiter in the PHP docs for more info).

- Jonathan

Author

Commented:
<FRAGMENT FROM PAGE 1>

<FORM action=polview2.php?v=<?php print $_GET['v'];  ?> method=POST>
<TABLE><TR><TD width=50%>
<B>Have you declared a major yet?</B><BR>
<SELECT NAME=majsure onChange="makeNextVisible(this);">
        <OPTION VALUE=0>Select One</OPTION>
        <OPTION VALUE=1>Yes</OPTION>
        <OPTION VALUE=2>No</OPTION>
</SELECT>

<BR><BR>
<SPAN ID=Egg2 Style="Visibility:hidden;">

<B>What is your primary major?</B><BR>

                        <SELECT NAME=major1>
                             <option value=0 selected>Select One</option>
                             <?php include('majors.inc');?>
                        </SELECT>
<BR><BR>
<B>If you are double majoring, what is your secondary major?</B><BR>
                        <SELECT NAME=major2>
                             <option value=100 selected>None</option>
                             <?php include('majors.inc');?>
                        </SELECT>

</SPAN>
</FRAGMENT FROM PAGE 1>

Author

Commented:
<FRAGMENT FROM PAGE 2>
        $major1 =  $_POST['major1'];
        $major2 =   $_POST['major2'];
   
        if (is_null($major1)){
            print "major1 is null";  #we have a problem
        }
         if (is_null($major2)){
             print "major2 is null";  #we have a problem
        }


</FRAGMENT FROM PAGE 2>

Author

Commented:
Note that I do have two questions which may be visible or hidden depending on the answers to previous questions.  I'm not sure if this is related to the problem or not.  

Author

Commented:
Do you guys think it would be appropriate to post a link to my site, or would you rather just have code fragments?

Commented:
I don't know if it's that strict or not, but don't you need to have your option values between parentheses?

<option value="100" selected>None</option>

Commented:
a link would be nice ... and add
<?php echo "<pre>";print_r($_POST);echo "</pre>"; ?>
at the begining of each page

Author

Commented:
I think I may have solved the problem, but I haven't tested it enough yet.   It seems like when I go to the first page using http:// it works fine, but when I use https:// it doesn't work.  Does this sound reasonable to anyone?

Commented:
Does the page you are requesting via https have an SSL certificate?

Author

Commented:
Yes, it does have an SSL certificate.

Commented:
If you are posting from http to https, this might trigger a cross-domain post restriction is transferring data from a secure to an insecure system and vice versa.

Author

Commented:
Well, it wasn't cross-domain because I only specified the script name, not the full URL in the ACTION attribute.  Nonetheless, I have tested this about 5-6 times and so far it always work when the first page is http and is intermittenly bad when the first page is https

Commented:
I know it's not cross-domain, but changing protocols could have an effect. Try submitting the form using the same protocol over both pages.

Author

Commented:
Isn't it always the same protocol given: <FORM action=polview2.php?v=<?php print $_GET['v'];  ?> method=POST>

Commented:
I'm afraid I'm stumped on this. If you are losing the POST data via https, but not http, then that's narrowed it down to an SSL problem, but buggered if I know what it is :(

Author

Commented:
Well, I'm not complaining if it works :).  I'll keep this question open for a few more days to see if my estimation of the problem is correct -- it may be something totally unrelated.

Commented:
Hi there,

     Sorry, but I have a question on drop down.  I have a dropdown box is populated with data retrieved from Oracle table.  

     When I select one of the values in the drop-down, I want to write the value to a text box.  Please advice as I could not get it to work (ie. to write to the text box.)

    Thanks in advace.

     Francis

Code for the program is as follows:

<SCRIPT type=text/javascript>
<!--
    function duplicate()
    {
            document.fm1_form.txt1.value = document.carno.value  ;
    }
   
    function duplicate1(textstr1)
    {
            document.fm1_form.txt1.value = textstr1;
    }
// -->
</SCRIPT>    

<?php
$db = "(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 130.0.0.100)(PORT = 1521)) ) (CONNECT_DATA = (SID = DEVL) ) )";
$conn = OCILogOn("mss", "mss",$db);

$query = 'select CPAR_NO, VEHICLE_NUMBER from mss_sing_complaints2004';

//$stmt = OCIParse($conn,"select CPAR_NO, VEHICLE_NUMBER from mss_sing_complaints2004");



//OCIExecute($stmt);
     $stid = OCIParse($conn, $query);
     OCIExecute($stid);

?>
<FORM name=fm1_form action=http://130.0.0.210/doinsert.php content="no" method=post>

<p>Vehicle Number:  <select name="carno">
<?
while (OCIFetchInto ($stid, $row, OCI_ASSOC))
{  
?>
<OPTION onchange=duplicate1("<?=$row["VEHICLE_NUMBER"] ?>") value="<?=$row["CPAR_NO"] ?>"><?=$row["VEHICLE_NUMBER"] ?>  </OPTION>

<?
}
?>
</select></p?>


<BR><BR>
<TBODY>
 
<TR>
<TD><input type="text" name="txt1"></TD></TR>
</BODY>
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
I think this might be the problem: http://web.wm.edu/it/?id=3312

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.