0

I have this code :

<?
    if(isset($_POST['wallib']) {
            $insert=mysql_query("INSERT INTO wall (message) VALUES ('".mysql_real_escape_string($_POST['wallib'])."')",$mydb);
    }
?>

<form action='index.php?explore=home' method='post' name='wallHome'>
    <input id="wallib" name="wallib" type="text" class="inputWall1" />
    <a href="javascript:document.wallHome.submit();">Send</a>
</form>

If i press quickly on Send (without waiting for the response, just quickly) I see that the message is inserted only 1 time on the Database.

But, if I add (for example) the function sleep(2); in the php script and I still click quickly on Send, it adds on the database the string for each click.

So I'm not so quickly in the fist case? Yeah, a stupid question... just curious... :)

markzzz
  • 47,390
  • 120
  • 299
  • 507

1 Answers1

1

Hard to say. This might be some race condition, and can depend on the browser behaviour. Might be for example that the second click ocurrs (inside the browser) about at the same time it is receiving/processing the response and preparing to render the ouput, and at that moment it invalidates any user input.

Depending on the browser you are using, you have development tools and plugins to debug all the browser-server conversation. It is also useful to look at the web server logs, to check how many requests your two clicks have triggered.

leonbloy
  • 73,180
  • 20
  • 142
  • 190
  • That's why I thought about a user that click (for example) 2-3 times on a button when a page is not rendered (maybe a slow connection) : in that case does he send 2-3 requests to the server? – markzzz Apr 17 '11 at 01:21
  • 2
    Normally, if the response is slow, if the user clicks again, another http request is sent (and the response of the first is lost). This is a nasty and well known problem, search for "double submit". For example http://stackoverflow.com/questions/2635652/how-can-i-prevent-a-double-submit-with-jquery-or-javascript or http://stackoverflow.com/questions/442678/preventing-double-http-post – leonbloy Apr 17 '11 at 01:25