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........ -
<form id="form1" name="form1" method="post" action="index.php">
-
Name:<input name="name" type="text" /><br />
-
Phone Number:<input name="pnumber" type="text" /><br />
-
<input type="submit" name="submit" value="submit" />
-
-
</form>
-
<?
-
$submit=addslashes($_POST['submit']);
-
if(isset($submit))
-
{
-
$name=addslashes($_POST['name']);
-
$pnumber=addslashes($_POST['pnumber']);
-
$sql="insert into details(phone,name) values ('$pnumber','$name')";
-
mysql_query($sql) or die('Could not Connect the database'.mysql_error());
-
echo"<script language=javascript>alert('Your details are stored successfully');</script>";
-
-
}
-
?>
-
Any body help me plz very urgent.........
thanks....
4 10523
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.
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: -
<?php
-
# Check if the $_GET['sent'] element is set
-
if(!isset($_GET['sent'])) {
-
# Process the data
-
# Note, for the header function to work, nothing can be
-
# printed before it is called!
-
header("Location: ?sent=true");
-
}
-
else {
-
echo "Your data has been added!";
-
}
-
?>
-
<form action="?" method="POST">
-
<!-- your fields here -->
-
</form>
-
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........... ..
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: -
<?php
-
# Check if the $_GET['sent'] element is set
-
if(!isset($_GET['sent'])) {
-
# Process the data
-
# Note, for the header function to work, nothing can be
-
# printed before it is called!
-
header("Location: ?sent=true");
-
}
-
else {
-
echo "Your data has been added!";
-
}
-
?>
-
<form action="?" method="POST">
-
<!-- your fields here -->
-
</form>
-
thanks for ur suggestions.... .
it is working now fine
Sign in to post your reply or Sign up for a free account.
Similar topics |
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!
|
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?
|
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
|
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.
|
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?
| |
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"...
|
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
|
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...
|
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...
|
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
|
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,...
| |
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...
|
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...
|
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,...
|
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();...
|
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...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |