guddoosk Posted June 6, 2009 Share Posted June 6, 2009 Hi all, I have recently started learning PHP and had been good till I reached forms. This is where I am stuck up - I have a simple contact me form that has 4 fields. After submitting the form I call a php script to update the data in a MySQL database. This part is ok. But the problem is that after update of the database, in case I click the refresh button, the data on the form gets resubmitted - that is after displaying data updated successfully, in case I refresh the page, the data just entered on the form is resubmitted and updated in the database. Any advice that I should try out? Thanks for the advice in advance Code of php script that gets called is <? $post_vars = $HTTP_POST_VARS; $uname = $post_vars['uname']; $email = $post_vars['email']; $related = $post_vars['related']; $feedback = $post_vars['msg']; $flag = true; //Validate the Input //........ if($flag) { //connect to the database //Create the Query/ Insert Statement $ins = "INSERT INTO feedback ("; $flds = "name, email, relatedto, feedback) VALUES("; $vals = '"' . $uname . '","' . $email . '","' . $related . '","' . $feedback . '")'; $statement = $ins . $flds . $vals; //Execute the statement $result=mysql_query($statement); if($result) { print("Data Updated Successfully"); $flag=true; } else { die("Could not insert the data in the database... <br />" . mysql_error()); $flag=false; } mysql_close($connection); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/161185-please-help-in-solving-a-simple-form-issue/ Share on other sites More sharing options...
.josh Posted June 6, 2009 Share Posted June 6, 2009 have your script check if info exists in db already, before you run your insert. pseudo code: select * from table where name = '$uname' or email = '$email' if (mysql_num_rows > 0) { echo "you already registered!" } else { insert ... } Quote Link to comment https://forums.phpfreaks.com/topic/161185-please-help-in-solving-a-simple-form-issue/#findComment-850553 Share on other sites More sharing options...
guddoosk Posted June 6, 2009 Author Share Posted June 6, 2009 have your script check if info exists in db already, before you run your insert. pseudo code: select * from table where name = '$uname' or email = '$email' if (mysql_num_rows > 0) { echo "you already registered!" } else { insert ... } Tx Crayon Violent. I understand that ths needs to be done. But as for this form, it is a feedback form and in such a case the fields $uname and $email may be duplicated. Yes, I can try for the $msg(feedback's) content getting duplicated but what i want is the problem to be solved at the client's system, that is, in case the browser / visitor presses F5 or refresh button on toolbar, the resend thing should not happen et all. Hope this is not asking too much from PHP. Quote Link to comment https://forums.phpfreaks.com/topic/161185-please-help-in-solving-a-simple-form-issue/#findComment-850598 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.