Jump to content

30-second rule for POST data?


brownshoe

Recommended Posts

I'm working on some scripts that get data from HTML forms via the "post" method.  The scripts take the post data and use it to do various basic SQL statements. (duh?)

 

However, I'm having a problem with them:  When I click "submit" on the form, the script on the next page behaves as if it is receiving no post data.  If I leave it alone for 30 seconds, then hit "refresh" on my browser (and resend post data), it finds the post data and works just like I wanted it to in the first place.

 

What's going on here, and what's the way around it?

Link to comment
Share on other sites

Here's a sample of the script that handles the post data:

 

//assign post information

$pilot=$_POST[PilotID];
$AircraftID=$_POST[AircraftID];
$registration=$_POST[registration];

//get info

$query="SELECT `UserID`, `first_name`, `last_name` from `users` WHERE `UserID`='$pilot'";

$result=mysql_query($query);

$row=mysql_fetch_array($result);

$firstname=$row["first_name"];
$lastname=$row["last_name"];

//remove row from authorized_pilots

$drop_query="DELETE FROM `authorized_pilots` WHERE `PilotID`='$pilot' AND `AircraftID`='$AircraftID' LIMIT 

1";

$drop_result=mysql_query($drop_query);


//echo success message and link back to homepage

echo "<p align=\"center\">$firstname $lastname is no longer authorized to fly $registration.<br>
<a href=\"pilothome.php\">Back to Pilot Homepage</a></p>";

 

This is the form that sends the information:

 

echo "<td>

<form action=\"drop_pilot.php\" method=\"post\">

<input type=\"hidden\" name=\"PilotID\" value=$PilotID>
<input type=\"hidden\" name=\"AircraftID\" value=$AircraftID>
<input type=\"hidden\" name=\"registration\" value=$registration>
<input type=\"submit\" value=\"Remove\"></form></td>";
echo "</tr>";

Link to comment
Share on other sites

Thanks for the help!

 

I know the backslashes are there for a reason  ;)

 

The form is actually part of a bunch of forms in a table (a script generates one for each row) like so:

while ($pilot_row=mysql_fetch_array($pilots)) {

$firstname=$pilot_row["first_name"];
$lastname=$pilot_row["last_name"];
$location=$pilot_row["location"];
$PilotID=$pilot_row["PilotID"];

echo "<tr>";
echo "<td>$firstname $lastname</td>";
echo "<td>$location</td>";
echo "<td>

<form action=\"drop_pilot.php\" method=\"post\">

<input type=\"hidden\" name=\"PilotID\" value=$PilotID>
<input type=\"hidden\" name=\"AircraftID\" value=$AircraftID>
<input type=\"hidden\" name=\"registration\" value=$registration>
<input type=\"submit\" value=\"Remove\"></form></td>";
echo "</tr>";

}

 

Is it cool to have more than one form on a page like that, or is that causing some kind of problem?  Like I said, if you wait 30 seconds, then hit "refresh" and then "resend post data" it works just fine.

 

 

Link to comment
Share on other sites

hmmm... that doesn't seem to matter... I tried single quotes and double quotes (with backslashes) and it's still doing the same thing.  What weirds me out is that it WORKS, you just have to refresh the page and resend the data for the script to find the post data.

Link to comment
Share on other sites

well thats a sign that the vars are not be filled until after the first POST are you sure the issues is not higher up where you are querying your DB for the relevant info to fill the form?

 

Try checking the source code before you submit at all to make sure there correct values are in the hidden fields.

Link to comment
Share on other sites

Ah ha!

 

Here's what's coming up in the source...

 

<form action="drop_pilot.php" method="post">

<input type="hidden" name="PilotID" value="$PilotID">
<input type="hidden" name="AircraftID" value="$AircraftID">
<input type="hidden" name="registration" value="$registration">
<input type="submit" value="Remove">

And such.  Looks like it's not showing the values right...

Link to comment
Share on other sites

Hmmm...

 

I got the values to show up in the source just by taking the quotes away.  The whole thing is part of a big "echo" statement, so I don't think I really need the "echo" in each field.

 

But it still hasn't solved the problem.  The HTML source is looking much more tidy...

 

<form action="drop_pilot.php" method="post">

<input type="hidden" name="PilotID" value=1>
<input type="hidden" name="AircraftID" value=2>
<input type="hidden" name="registration" value=N348SP>
<input type="submit" value="Remove"></form>

 

So yeah... got THAT problem fixed.  Still have to wait 30 seconds (I'm serious... I'm timing it) and then refresh the page to make it work.

Link to comment
Share on other sites

Seems to work fine as long as I wait a while between posts.  Could it be something with the browser or the server storing the data for 30 seconds?  Is there some way to force it to clear itself so a new post can be entered?

 

Thanks for the help, bendude.  I'm sure the thing with not displaying the right values in the hidden fields had SOMETHING to do with it.  Runs better now, but still hafta wait a little.

 

I'm off to bed.  Thanks again!

Link to comment
Share on other sites

DB query is pretty simple...

 

$pilots_query="SELECT `authorized_pilots`.`PilotID`, `authorized_pilots`.`AircraftID`, `users`.`UserID`, 

`users`.`first_name`, `users`.`last_name`, `users`.`location`  FROM `authorized_pilots`, `users` WHERE 

`users`.`UserID`=`authorized_pilots`.`PilotID` AND `authorized_pilots`.`AircraftID`='$aircraft' ORDER BY 

`users`.`first_name` ASC";

 

Since the form is on a page that takes post data from a form on the previous page to itself, is it possible the old post data remains valid for 30 seconds and somehow blocks the new stuff?  It just seems really strange to me that the post data won't be sent for 30 seconds.  You can either let the page with the form sit for 30 seconds, or refresh the target page 30 seconds after you submit.  Do I need to somehow close my scripts or something?  I'm guessing since PHP is a server-side language that this 30 second thing has something to do with the server.  Is there some way I can manually make my post data from the previous form expire sooner?

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.