开发者

Why this behaviour on submit?

I have this code :

<?
    i开发者_运维百科f(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... :)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜