Hi,
I have refresh problem.When user does refresh or clicks F5 then form variables again posting. It crates same a lot of inserts. I don't know How to solve it.
14 2083 ak1dnar 1,584
Recognized Expert Top Contributor
I think you are using a html form to submit the data and there might be a submit button.
Let's assume that submit button is like this.
[HTML]<input type="submit" name="sub" value="Send">[/HTML]
then from your php side use like this.
[PHP]if ($_POST['sub'])
{
// insert current coding inside this if block for getting values from html form and //inserting it to the database
}[/PHP]
php will execute only user cllicks the sub button .
I have already done it. My code sample;
Submit buton definition <input type="submit" name="kaydet" value="Kaydet">
insertion side
if($_POST['kaydet'] )
{
// I'm taking POST variables and inserting to database
}
ak1dnar 1,584
Recognized Expert Top Contributor Purple 404
Recognized Expert Contributor
Hi seralasu,
I am assuming you are still having a problem with this.. a suggestion is to use Javascript on the onClick event of your submit button and set a hidden field on your form and test that rather than the submit button - the onClick event will only fire when clicked - ie it does not fire on refresh / F5..
the following code demonstrates using a basic javascript alert..
[PHP]
echo "<form name=\"test\" action=\"".$_SE RVER["PHP_SELF"]."\" method = \"post\">
<input type=\"submit\" name=\"kaydet\" value=\"Kaydet\ " onClick=\"javas cript:alert('he re');\"></input></form>";
print_r($_POST) ;
[/PHP]
Hi,
Please check the thread http://www.thescripts. com/forum/thread576526.ht ml
Subash :)
Purple 404
Recognized Expert Contributor
Hi Subash,
I don't think the thread you referenced answers the initial issue - the problem experience is caused by hitting refresh or F5 on a form using a method of post - basically the form is submitted every time the form is refreshed, F5 is hit or the submit button is pressed..
Rgds Purple
pbmods 5,821
Recognized Expert Expert
Easiest way I can think of to prevent this is to set up some unique keys in MySQL.
For example, suppose you had a table that looked something like this: -
mysql> DESCRIBE `Data_Categories`;
-
+------------+---------------------+------+-----+---------+----------------+
-
| Field | Type | Null | Key | Default | Extra |
-
+------------+---------------------+------+-----+---------+----------------+
-
| categoryid | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
-
| desc | varchar(64) | NO | | | |
-
+------------+---------------------+------+-----+---------+----------------+
-
Obviously, it wouldn't be useful to have a bunch of duplicate categories (this is an example; bear with me). So we would want to add a unique constraint so that every category has a different name.
To set up a unique key: -
ALTER TABLE `Data_Categories` ADD UNIQUE KEY `catName`(`desc`);
-
The `catName` is just the name of your key and can be just about anything you want it to be. You put the name of the column(s) you want constrained inside the parenthesis.
Once the unique is in place, attempting to insert a duplicate row will fail: -
mysql> INSERT INTO `Data_Categories` (`desc`) VALUES('Tester');
-
Query OK, 1 row affected (0.00 sec)
-
-
mysql> INSERT INTO `Data_Categories` (`desc`) VALUES('Tester');
-
ERROR 1062 (23000): Duplicate entry 'Tester' for key 2
-
[EDIT: Just to make things complicated, you can put a constraint on more than one column in the table. For example, if you used: -
ALTER TABLE `Data_Categories` ADD UNIQUE KEY `parentData`(`parent`, `desc`);
-
(assuming that `Data_Categorie s` also had a `parent` field)
Then an INSERT would only fail if you tried to add a row with the same `parent` AND `desc` as an existing row, but would still allow the INSERT if only one of the fields matched.]
Hi,
Thanks for all replies. I will try them.
To AJAXRAND (sorry - I could not post this as a reply to your comment)
It does not work. Your $_POST['sub'] will be still there (the form will be sent again with F5 - refresh).
Have a try to add at the end of your PHP script this:
echo "<PRE>POST :";
print_r($_POST) ;
echo "</PRE>";
Paja
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: James |
last post by:
I have a data grid refresh problem. I have a few columns and the first
column is data in the form of numbers. And in the form of the data
grid if I specify for example something like a code(in a text box) the
column of numbers should change colors depending on whether the number
was in the specified code(if it belongs to the code, color the cell
(first column) in Red and if not in some other color). It all works
out fine until I scroll...
|
by: wright |
last post by:
hello, i have a problem in refreshing a page. the problem happens when i
click a button that does a certain action in a web page, such as inserting a
record into the database, if now i refresh the page (press f5), the action
repeats itself and another identical record is inserted too.
i discovered that the button_click event is called when i refresh the page.
so the problem is that when i refresh the page, the last action that i have
done...
|
by: sandhya.net |
last post by:
Hi,
I have a dropdown which displays the Products and Add button on my
Asp.net web page. When the user selects a product from the dropdown
and
Clicks the add button it adds the selected product to the datagrid.
The problem is when the user adds the product and clicks the refresh
button on the browser,the same item is added to the datagrid once
again. How to prevent calling Add_click Event when the refresh is
|
by: Bernie Hunt |
last post by:
I have a simple app that grabs records from a database and steps through
them processing each record. I have three text fields on the form to give
the user feedback on the progress.
With each new record I update the three fields on the form with the
information from the current record. I initially wasn't getting the fields
updated, so I added a .refresh() for each field as new data was added.
The problem is when the form loses focus,...
|
by: George |
last post by:
Hi,
I have been encountering a refresh problem with DataGridView, which is bound
to a DataTable.
When I make updates (Add, Delete, update) to the DataGridView, everything
flow nicely to DataTable. No problem here.
However, when I add data (programatically) to the DataTable, the
DataGridView does not refresh right away. If I minimize and show my form,
| |
by: khurram.shakir |
last post by:
I am developing an application, which uses .NET 2.0/WinForms and has a
designer for screen layout designing. User has an option to design the
layout of screen, and for that we developed our own controls based on
UserControl Class. After the designing the layout is saved as an XML,
and we have a Loader of XML that renders the layout afterwards.
When we load the controls and layout from xml, every thing works fine
except we are facing...
|
by: shekharanjali |
last post by:
hi,
i have a page refresh problem , when the page is refreshed the last query or the command gets executed, is this problem something to do with cookies.please reply.
thanks
|
by: jackb |
last post by:
Hello there.
I have a webpage that need to reload every 10 seconds, so I have put a meta tag:
<meta http-equiv="refresh" content="10">
Now this seems to work ok.
Now the problem is that my application requires to be monitored most time of the day and some users have reported that the refresh thing stops working after some time in the day.
So is there any problem in the meta refresh so that if it is allowed to refresh for many hours...
|
by: EManning |
last post by:
Using A2003 w/ tables linked to SQL Server. All users have their own
copy of the mdb. I have a combobox whose rowsource is a query. This
query is based on a table and has a field in it that indicates if the
record has been selected. When user1 selects the record from the
combobox, the field is updated that the record has been selected. If
user2 tries to select that same record, they get a warning that user1
has selected it and...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |