473,805 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to prevent form data being re-submit when page is refreshed?

ganesanji
16 New Member
Hi,


I have written a simple php coding for getting the name , phone number and insert the values into data base. My problem is that when ever I just click the refresh button in the browser window, it will automatically previous inserted values are once again inserted into databse as a new entry.

Please anybody give the perfect coding which will avoid automatic insertion of previous values into database.....

I attched my coding below........
Expand|Select|Wrap|Line Numbers
  1. <form id="form1" name="form1" method="post" action="index.php">
  2. Name:<input name="name" type="text" /><br />
  3. Phone Number:<input name="pnumber" type="text" /><br />
  4. <input type="submit" name="submit" value="submit" />
  5.  
  6. </form>
  7. <?
  8. $submit=addslashes($_POST['submit']);
  9. if(isset($submit))
  10. {
  11. $name=addslashes($_POST['name']);
  12. $pnumber=addslashes($_POST['pnumber']);
  13. $sql="insert into details(phone,name) values ('$pnumber','$name')"; 
  14. mysql_query($sql) or die('Could not Connect the database'.mysql_error());
  15. echo"<script language=javascript>alert('Your details are stored successfully');</script>";
  16.  
  17. }
  18. ?>
  19.  
Any body help me plz very urgent.........

thanks....
Sep 27 '07 #1
4 10523
shane3341436
63 New Member
Yes it is the problem while refreshing the page.
Why don't you try to empty all the fields when the query is successful.
Or you can redirect the page to another page when the query is successful.
Or you can add a hidden field whose value u can set when clicking the submit button. Then you can check that hidden value while inserting the values.
Sep 27 '07 #2
Atli
5,058 Recognized Expert Expert
Hi.

In this case, I would recommend submitting the form to a different page, which would then process the data.

If, however, you need to keep it all in the same form, consider something like this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.   # Check if the $_GET['sent'] element is set
  3.   if(!isset($_GET['sent'])) {
  4.     # Process the data
  5.     #  Note, for the header function to work, nothing can be
  6.     #  printed before it is called! 
  7.     header("Location: ?sent=true");
  8.   }
  9.   else {
  10.     echo "Your data has been added!";
  11.   }
  12. ?>
  13. <form action="?" method="POST">
  14.   <!-- your fields here -->
  15. </form>
  16.  
Sep 27 '07 #3
ganesanji
16 New Member
Yes it is the problem while refreshing the page.
Why don't you try to empty all the fields when the query is successful.
Or you can redirect the page to another page when the query is successful.
Or you can add a hidden field whose value u can set when clicking the submit button. Then you can check that hidden value while inserting the values.
thanks......... .
now its working fine........... ..
Sep 28 '07 #4
ganesanji
16 New Member
Hi.

In this case, I would recommend submitting the form to a different page, which would then process the data.

If, however, you need to keep it all in the same form, consider something like this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.   # Check if the $_GET['sent'] element is set
  3.   if(!isset($_GET['sent'])) {
  4.     # Process the data
  5.     #  Note, for the header function to work, nothing can be
  6.     #  printed before it is called! 
  7.     header("Location: ?sent=true");
  8.   }
  9.   else {
  10.     echo "Your data has been added!";
  11.   }
  12. ?>
  13. <form action="?" method="POST">
  14.   <!-- your fields here -->
  15. </form>
  16.  

thanks for ur suggestions.... .
it is working now fine
Sep 28 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
3157
by: John | last post by:
How do I prevent blank data from being entered into a table? For instance, the user fills out a form, but if a field is left blank, then the entire entry won't be filled in. This isn't necessarily a form validation thing, just that if all the fields are filled, then proceed to enter data, if not then don't. Thanks in advance!
1
2700
by: Job Lot | last post by:
How can I prevent multiple instances of MdiChild form? I have a MdiParent form with a DataGrid showing all the clients in the database. User clicks on a row to open MdiChild form which display details of the client. User can have multiple clients open at the same time, but how can I prevent them from opening multiple instances of the client?
5
1755
by: Morris | last post by:
This may not be possible on the server side, so apologies if this is the wrong group for this post. My form consists of an unknown number of pairs of text boxes. They are named textbox_a and textbox_b. I then split the comma separated list that gets posted: textbox_a = split(Request.Form("textbox_a"),",") for i = ubound(textbox_a) ...insert into db
6
6589
by: Miguelito Bain | last post by:
hi everybody- i have a form with 2 fields on it that i want the user to fill out before he or she can save the record, close the record, or move to the next record, etc... here's the code i tried. if i just enter minutes and click close, the form closes. it seems to bypass my nested if statement.
3
2233
by: Randy | last post by:
I want to set up a table where I can enter dates that will prevent data entry of Dates in the Main table. I have done this in Approach by linking two tables and setting up a validation formula IsBlank (Date.Date). After staff enter dates in the detail table it will prevent dates in the Main table. How can I do that in Access?
10
14900
by: hendedav | last post by:
Gang, I am not quite sure if this has been posted before. I have searched google groups and couldn't find anything. I am trying to setup a container div that contains columns of divs (to generate a "spreadsheet". Each "cell" can contain either text or an object. My problem is that when I generate columns that run outside of the width of the container div, the following div's wrap. I have tried using <nobrtags, "white-space: nowrap"...
11
5359
by: ariel81 | last post by:
i have created a function to input data from four textboxes into a table. how do i prevent duplicate records of the same mth/Yr into the table? editing of the data in the table with reference to the mt/Yr is allowed, but how to prevent duplicate records? Public Sub PutInMonthlyRecords() Dim sql As String Dim Db As DAO.Database Dim rs As DAO.Recordset Dim f As Form Dim MthYr As String
3
3222
by: MyWaterloo | last post by:
Heya... Thanks in advance if you can help... or at least understand my gibberish. I have 2 tables, let's call them tblBacT and tblBacTData, they are related through the auto number primary key "entryId" in tbleBacT. I have created a form (frmBacT) and sub form (subfrmBacTData) with the sub from in columnar view. Kiddie stuff right? My problem is: I don't want the user to be able to enter data in the sub form and then exit or move on to...
1
2006
by: MyWaterloo | last post by:
Hey, I'm trying to figure out how to prevent entry into a new record on a data sheet or columnar sub form. I want the user to finish the record they are working on before moving on to the next. The records do not have required fields just a primary key auto number to give them a unique field. Maybe a check box to select done with current record make the next one visible/enabled? Is anything like this possible in a data sheet/columnar...
1
1523
by: sennopati | last post by:
Dear, I have looping statement like this: For Each frmChild As Form In Me.MdiChildren 'Ada validasi untuk periksa status data(sudah disimpan atau belum) frmChild.Close() frmChild = Nothing Next
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10607
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10359
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6875
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5541
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4317
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3843
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.