Jump to content

Script being run thru twice when a SUBMIT button is selected


ICubis2

Recommended Posts

I have a problem that is particular to the FF and Safari browsers.  I do not see the problem in IE.

 

Again, I am very new to php programming - no formal training - just a hacker.

 

I have a web page that presents a form with a results table and a SUBMIT button.  Each time the button is selected I want to present one of two different tables of results. 

 

Everything works fine the first time I hit the SUBMIT button.  The page updates and shows the second table.

 

But on the next SUBMIT the script that swaps things around is executed twice in FF and Safari vs. one time like in EI.

 

This results in the same result table being displayed over and over vs. the two switching back and forth.

 

Any idea what could be going wrong in these two browsers?

 

Here's my swap script:

 

<?php
session_start();
// This script reverses the coin flip to see what would happen the other way
if ($_SESSION['Coin_Flip'] == "heads") { //switch to tails
  $_SESSION['Coin_Flip'] = "tails";
  include ('tails_algo.php');
} elseif ($_SESSION['Coin_Flip'] == "tails") {
  $_SESSION['Coin_Flip'] = "heads";
  include ('heads_algo.php');
}
include ('kind-comp_result.php');
?>

 

 

Link to comment
Share on other sites

Any idea what could be going wrong in these two browsers?

Probably nothing.  :)

 

I say -> program in FF and then see what IE has done with it. FF is far more compliant with the rules.

Your included code does not show the problem. Maybe heads_algo.php or kind-comp_result.php does

Link to comment
Share on other sites

The user selects a radio button in the beginning of the process to set the coin flip - either heads or tails.

 

The initial results table show the result correctly.  Also the first time the swap coin flip SUBMIT button is activated it works fine and shows the opposite.

 

The problem is on the next activation of this same button.

 

$_SESSION['Coin_Flip']  becomes  the same thing (either heads or tails) because the script is being run through twice.

 

Again, EI works correctly and only runs through the script once, so the user can toggle back and forth between the heads and tails results tables.  FF and Safari start double executing the script on on each activation of the button from the 2nd time onward.

Link to comment
Share on other sites

Here's the section of HTML for the page the presents the results table:

 

<div id="e16" style="position:absolute;left:177;top:147;width:418;height:573;"><script type="text/javascript">
function checkForm16() {
  return true;
}
</script>
<?php

echo "<form action='other_flip.php' method='post'>";
echo "<table border='1'>";
echo "<tr><th colspan='2'>Your competition results.</th></tr>";
echo "<tr> <th bgcolor ='#FFFF00'>Winning Team</th> <th>2nd Place Team</th></tr>";
echo "<tr> <th bgcolor ='#FFFF00'>".$_SESSION['win_num']."</th> <th>".$_SESSION['2nd_num']."</th></tr>";
$count =1;
while ($count <= $_SESSION['rows']){
  echo "<tr><td valign ='top'>"; 
  echo "<tr><td bgcolor ='#FFFF00'>".$_SESSION['winner'][$count]."</td><td>".$_SESSION['second'][$count]."</td></tr>";
  echo "</td><td valign ='top'>"; 
  echo "</td></tr>";
  $count++;
}
echo "<input type='submit' value='What if - opposite flip?'>";
echo "</table>";
echo "</form>";
//reset button
echo "<form action='kind-comp_input.php' method='post'>";
echo "<input type='submit' value='Start Over'>";
echo "</form>";

?>
<!--$end exclude$-->      
</div>

Link to comment
Share on other sites

S$%t - I apologize.  This problem is being caused by the same HTML code that gave me the other problem.  Somehow I reverted back to that other code without the fix.  (All those lines of code commented out.)  Making the fix again did take care of the problem.

 

Again, sorry for wasting your time on this one.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.