geroido Posted August 6, 2008 Share Posted August 6, 2008 Hi all I have a webpage where the user can enter menu items(name, description, price etc.) and they are inserted into a database on clicking the 'save' submit button. It all works well. However, if I enter the information and click save, it works but if I then refresh the page, it puts the record into the database again and again and again if I keep refreshing which I don't want. Can you give me an idea what might be the problem. I'm not including any code now, just looking for ideas. I can submit the code if it helps. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted August 6, 2008 Share Posted August 6, 2008 you want the person to only submit the form once then kill the form? use javascript. Quote Link to comment Share on other sites More sharing options...
geroido Posted August 6, 2008 Author Share Posted August 6, 2008 Hi MasterACE14 Thanks but I don't want to kill the form because as soon as the record is inserted I am presenting the user with the form again to enter another record. They exit by using the 'cancel' submit button. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted August 6, 2008 Share Posted August 6, 2008 you could put whatever they insert the first time into a session variable, then when they submit the form again, check what they submit, against the session variable to make sure it doesn't match. Quote Link to comment Share on other sites More sharing options...
geroido Posted August 6, 2008 Author Share Posted August 6, 2008 That sounds like a good idea. I'll try that. Thanks Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted August 6, 2008 Share Posted August 6, 2008 Any user can repeatedly submit a form if they know what they're doing. All they gotta do is revisit the page that processing was done on. What I'd suggest is before doing an insert, do a query searching for a row with all of the inputted credentials that are exactly the same. If you get a mysql_num_rows() > 0 then you can know if was refreshed and then skip the INSERT query. That's really the only way to protect refreshing from inserting multiple times. Quote Link to comment Share on other sites More sharing options...
geroido Posted August 6, 2008 Author Share Posted August 6, 2008 Hi dannyb785 I think that's a good idea too. I have a couple of options now so thanks for that. Do you also think it would be possible to clear all the variables after insert so that the form validation would fail and therefore present the user with the form again for completion but as a result of failed validation would not do any insert? Quote Link to comment Share on other sites More sharing options...
0siris Posted August 6, 2008 Share Posted August 6, 2008 yup, you should be able to do, after your insert statement set all the values to "", and then before inserting I presume you have a bit of code which prevents blank entries? Quote Link to comment Share on other sites More sharing options...
geroido Posted August 6, 2008 Author Share Posted August 6, 2008 What kind of code would prevent a blank entry? Quote Link to comment Share on other sites More sharing options...
lynxus Posted August 6, 2008 Share Posted August 6, 2008 $blaa = $_POST["blaa"]; $error = "0"; if ($blaa == "") { $error = "1"; } ?? Maybe thats completely not what you want ? Quote Link to comment Share on other sites More sharing options...
0siris Posted August 6, 2008 Share Posted August 6, 2008 something like: foreach($_POST as $field => $value) { if($value == "") { $blankarray[]; } } if(sizeof($blankarray) == 0) { die("There are blank fields"); //put or do whatever you want here } Quote Link to comment Share on other sites More sharing options...
geroido Posted August 6, 2008 Author Share Posted August 6, 2008 Thanks all I think I have enough to work with there. Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted August 6, 2008 Share Posted August 6, 2008 or just: unset($_POST); that should do the trick Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.