PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
From time to time I found duplicated records (rows) in my database. Its looks like the user double click on the submit button.
recently its happen more often so I add code that check when the last submit happened (I save the linux time) and check if there is 10 second delay:
$query = mysql_query("SELECT create_date FROM `tkts_topics` WHERE (client = '$client') AND (email = '$email') AND (title = '$title') AND ($date - create_date <= 10) LIMIT 0,1");
if (mysql_num_rows($query))
{
}
I don't know why but its not working.
is there any better way to prevent double submiting?
Server-side there are a couple common options:
- Check for recent duplicate data. Certainly easier to do but it might not always be possible.
- Generate a random ID, stick that in the session and hide it in the form, and when the form is submitted check that the ID hasn't been "used" yet. That could be the fact that it's still stored in the session: if it's set then the ID is valid, you do the work, and unset it, and if it's not set then you know the form was submitted twice.
What can happen is also when you submit forms, and the user refreshes the "loading" page he submits the data again. A solution to this can be to redirect the user with header(); to a page that confirms the submission (submitconfirm.php?submitid=XXX <- if you need the data reviewed/confirmed without the risk of submitting it again).