Link to home
Start Free TrialLog in
Avatar of Igiwwa
Igiwwa

asked on

Form Data is Empty but then Populated on Refresh

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!
Avatar of psycle
psycle

Post some of your code - a condensed version at least.
change your browser cache settings or try another browser .... or at least post some code
Avatar of gr8gonzo
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
Avatar of Igiwwa

ASKER

<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>
Avatar of Igiwwa

ASKER

<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>
Avatar of Igiwwa

ASKER

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.  
Avatar of Igiwwa

ASKER

Do you guys think it would be appropriate to post a link to my site, or would you rather just have code fragments?
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>
a link would be nice ... and add
<?php echo "<pre>";print_r($_POST);echo "</pre>"; ?>
at the begining of each page

Avatar of Igiwwa

ASKER

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?
Does the page you are requesting via https have an SSL certificate?
Avatar of Igiwwa

ASKER

Yes, it does have an SSL certificate.
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.
Avatar of Igiwwa

ASKER

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
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.
Avatar of Igiwwa

ASKER

Isn't it always the same protocol given: <FORM action=polview2.php?v=<?php print $_GET['v'];  ?> method=POST>
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 :(
Avatar of Igiwwa

ASKER

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.
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>
ASKER CERTIFIED SOLUTION
Avatar of cracky
cracky

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Igiwwa

ASKER

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