I’ve got an HTML form that adds data into a MySQL database. The form runs a PHP script if the form is submitted and the script is on the same page. If the user’s connection times out during the submission then an error is displayed. This is primarily to prevent bots from adding data even though the form isn’t displayed if a user isn’t logged in. Anyway I call the script from the same PHP file so that any messages etc are displayed on the same page when the form is submitted saving the user having to click return. However, the page uses a variable to display content so I just call the variable in the <form action=”index.php?id=”.$id.”\” /> so that whatever page the user submitted the form from will return to the same page. However, the user can refresh the page once the form has been submitted and this results in the data being added into the database again. How do I stop the user from being able to refresh the script that submits the form once it’s already been submitted?
It's okay, I just user a header in the script to return to the page and that fixed it. However, now I can't display a message to confirm that the user has succesfully submitted the form.
I'm going to use a seperate file for the script and then use the header(location: "") to redirect to the previous page. Because it's a seperate script should I submit the id variable on the form page as a hidden input in the form? Sorry, I'm new to PHP but I'll try it anyway. I just don't want to develop any bad scripting habbits.
User Form Refresh Re-enters Data
Moderator: General Moderators
-
Marinusjvv
- Forum Commoner
- Posts: 29
- Joined: Wed Dec 02, 2009 5:59 am
Re: User Form Refresh Re-enters Data
How about some code as an example?