I have a working PHP/MySQL application used for data entry. The data
entry screen includes a "Save" button. The PHP code for this button
looks like this:
if (isset($_POST['cmdSave']))
{
if ($_POST[txtStateFileNumber] == "")
{
include ("InsertRecord.inc"); // Insert new record
}
else
{
include ("UpdateRecord.inc"); // Update existing record
}
}
This works great. If the State File Number (primary ID) field is
blank, a new record is added and a new State File Number assigned,
otherwise the existing record is updated. However, if the user enters
some data and clicks "Save" to insert a new record and then clicks the
browser (IE) Refresh button, the insert logic is repeated and another
record is added to the database. Apparently, the cmdSave button
remains set and pressing Refresh executes the "InsertRecord" logic
again. The "Post" version of State File Number also remains blank
even though it exists on the screen after "Save".
I have tried quite a number of fixes for this problem, none of which
have worked satisfactorily. What I would like to do is reset the
cmdSave button after the InsertRecord logic executes. Is that
possible?
Alternately, if I could sense that the Refresh button had been clicked
rather than cmdSave, I could also prevent re-execution.
Register_globals is off.
Any suggestions are greatly appreciated. 9 4846
Uzytkownik "Mark" <hi***********@yahoo.com> napisal w wiadomosci
news:5e**************************@posting.google.c om... I have a working PHP/MySQL application used for data entry. The data entry screen includes a "Save" button. The PHP code for this button looks like this:
if (isset($_POST['cmdSave'])) { if ($_POST[txtStateFileNumber] == "") { include ("InsertRecord.inc"); // Insert new record } else { include ("UpdateRecord.inc"); // Update existing record } }
This works great. If the State File Number (primary ID) field is blank, a new record is added and a new State File Number assigned, otherwise the existing record is updated. However, if the user enters some data and clicks "Save" to insert a new record and then clicks the browser (IE) Refresh button, the insert logic is repeated and another record is added to the database. Apparently, the cmdSave button remains set and pressing Refresh executes the "InsertRecord" logic again. The "Post" version of State File Number also remains blank even though it exists on the screen after "Save".
I have tried quite a number of fixes for this problem, none of which have worked satisfactorily. What I would like to do is reset the cmdSave button after the InsertRecord logic executes. Is that possible?
Alternately, if I could sense that the Refresh button had been clicked rather than cmdSave, I could also prevent re-execution.
Register_globals is off.
Any suggestions are greatly appreciated.
Its because when user clicks refresh is posting form post data again.
Force reload page after manipulate with all post data like this:
if (isset($_POST['cmdSave']))
{
if ($_POST[txtStateFileNumber] == "")
{
include ("InsertRecord.inc"); // Insert new record
}
else
{
include ("UpdateRecord.inc"); // Update existing record
}
Header("Location: {$_SERVER['REQUEST_URI']}");
die;
}
It will reload your page and clean up all post data - when user will click
refresh button
it will post empty data so your "if (isset($_POST['cmdSave']))" won't catch
it.
Drizzt
"Mark" <hi***********@yahoo.com> wrote in message news:5e**************************@posting.google.c om... I have a working PHP/MySQL application used for data entry. The data entry screen includes a "Save" button. The PHP code for this button looks like this:
if (isset($_POST['cmdSave'])) { if ($_POST[txtStateFileNumber] == "") { include ("InsertRecord.inc"); // Insert new record } else { include ("UpdateRecord.inc"); // Update existing record } }
This works great. If the State File Number (primary ID) field is blank, a new record is added and a new State File Number assigned, otherwise the existing record is updated. However, if the user enters some data and clicks "Save" to insert a new record and then clicks the browser (IE) Refresh button, the insert logic is repeated and another record is added to the database. Apparently, the cmdSave button remains set and pressing Refresh executes the "InsertRecord" logic again. The "Post" version of State File Number also remains blank even though it exists on the screen after "Save".
I have tried quite a number of fixes for this problem, none of which have worked satisfactorily. What I would like to do is reset the cmdSave button after the InsertRecord logic executes. Is that possible?
Alternately, if I could sense that the Refresh button had been clicked rather than cmdSave, I could also prevent re-execution.
Register_globals is off.
Any suggestions are greatly appreciated.
One way to solve this problem is to redirect the browser to a new page
using header() function after the submission.
More elegant:
Place a hidden field with a random value.
In the script called after submit the form, place a SELECT before the INSERT
to check if this random value exists.
If so, return a message saiyng something like 'the data is already stored'
oh, simply, don't do anything.
En las nuevas, Mark escribió: I have a working PHP/MySQL application used for data entry. The data entry screen includes a "Save" button. The PHP code for this button looks like this:
if (isset($_POST['cmdSave'])) { if ($_POST[txtStateFileNumber] == "") { include ("InsertRecord.inc"); // Insert new record } else { include ("UpdateRecord.inc"); // Update existing record } }
This works great. If the State File Number (primary ID) field is blank, a new record is added and a new State File Number assigned, otherwise the existing record is updated. However, if the user enters some data and clicks "Save" to insert a new record and then clicks the browser (IE) Refresh button, the insert logic is repeated and another record is added to the database. Apparently, the cmdSave button remains set and pressing Refresh executes the "InsertRecord" logic again. The "Post" version of State File Number also remains blank even though it exists on the screen after "Save".
I have tried quite a number of fixes for this problem, none of which have worked satisfactorily. What I would like to do is reset the cmdSave button after the InsertRecord logic executes. Is that possible?
Alternately, if I could sense that the Refresh button had been clicked rather than cmdSave, I could also prevent re-execution.
Register_globals is off.
Any suggestions are greatly appreciated.
I use a seperate save script that, after saving the data, uses javascript to
redirect back to the form or wherever it needs to go.
// inputform.php
<form method=post action=saveit.php>
Data 1: <input type=data1>
<input type=submit>
</form>
// saveit.php
// search records for match
// update if match, new record if not
<script language="JavaScript">
alert('Data has been updated');
location.href = 'inputform.php';
</script>
"Mark" <hi***********@yahoo.com> wrote in message
news:5e**************************@posting.google.c om... I have a working PHP/MySQL application used for data entry. The data entry screen includes a "Save" button. The PHP code for this button looks like this:
if (isset($_POST['cmdSave'])) { if ($_POST[txtStateFileNumber] == "") { include ("InsertRecord.inc"); // Insert new record } else { include ("UpdateRecord.inc"); // Update existing record } }
This works great. If the State File Number (primary ID) field is blank, a new record is added and a new State File Number assigned, otherwise the existing record is updated. However, if the user enters some data and clicks "Save" to insert a new record and then clicks the browser (IE) Refresh button, the insert logic is repeated and another record is added to the database. Apparently, the cmdSave button remains set and pressing Refresh executes the "InsertRecord" logic again. The "Post" version of State File Number also remains blank even though it exists on the screen after "Save".
I have tried quite a number of fixes for this problem, none of which have worked satisfactorily. What I would like to do is reset the cmdSave button after the InsertRecord logic executes. Is that possible?
Alternately, if I could sense that the Refresh button had been clicked rather than cmdSave, I could also prevent re-execution.
Register_globals is off.
Any suggestions are greatly appreciated.
Of course then any back-button click will cause it to resubmit the data, you
could send it to a self closing pop-up window or use a webbug like below.
// getdata.php
<script language="JavaScript">
function setMe(){
var d1=document.getElementById('d1').value;
// I would probably add some form verification here
document.getElementById('dot').src='saveit.php?d1= '+d1;
alert('Data Saved');
document.getElementById('d1').value='';
}
</script>
Data 1 <input type=text id=d1><br>
<input type=button value='Save' onClick="setMe();">
<img id=dot src='dot.png' style='display:none'>
// saveit.php
<?php
// Put your data verification and save here
Header("Content-type: image/png");
$image = ImageCreate(5,5);
$bg = ImageColorAllocate($image,0,150,0);
imagefilledrectangle($image, 0,0, 5,5, $bg);
ImagePNG($image,'',100);
ImageDestroy($image);
?>
You have to have gd library active in your php.ini
The image color or size does not really matter as it is hidden by the
style='display:none'.
You could use the image to signal the save if you wanted to, I have used a
yellow image before the save and then changed it to green to show it was
saved.
"Arg" <r_***@hotmail.com> wrote in message
news:10*************@corp.supernews.com... I use a seperate save script that, after saving the data, uses javascript to redirect back to the form or wherever it needs to go.
// inputform.php <form method=post action=saveit.php> Data 1: <input type=data1> <input type=submit> </form>
// saveit.php // search records for match // update if match, new record if not <script language="JavaScript"> alert('Data has been updated'); location.href = 'inputform.php'; </script>
"Mark" <hi***********@yahoo.com> wrote in message news:5e**************************@posting.google.c om...I have a working PHP/MySQL application used for data entry. The data entry screen includes a "Save" button. The PHP code for this button looks like this:
if (isset($_POST['cmdSave'])) { if ($_POST[txtStateFileNumber] == "") { include ("InsertRecord.inc"); // Insert new record } else { include ("UpdateRecord.inc"); // Update existing record } }
This works great. If the State File Number (primary ID) field is blank, a new record is added and a new State File Number assigned, otherwise the existing record is updated. However, if the user enters some data and clicks "Save" to insert a new record and then clicks the browser (IE) Refresh button, the insert logic is repeated and another record is added to the database. Apparently, the cmdSave button remains set and pressing Refresh executes the "InsertRecord" logic again. The "Post" version of State File Number also remains blank even though it exists on the screen after "Save".
I have tried quite a number of fixes for this problem, none of which have worked satisfactorily. What I would like to do is reset the cmdSave button after the InsertRecord logic executes. Is that possible?
Alternately, if I could sense that the Refresh button had been clicked rather than cmdSave, I could also prevent re-execution.
Register_globals is off.
Any suggestions are greatly appreciated.
Thanks for all the helpful suggestions. The problem with the redirect
(Header) idea is that it clears all the data from the screen. What I
want is for the data to remain on the screen so the user can continue
with entry. There is a great deal of data (12 screens), so it is
reasonable to expect the user to save several times during the entry
of a record.
As it currently exists, my InsertRecord.inc logic contains some code
that rereads the record after the Insert:
// Reread the record after the POST operation
// Fields on form are refreshed after the reread via HTML "Value"
clauses
$sql = "SELECT * FROM rosemaster
WHERE StateFileNumber = $NewSFN";
$result = mysql_query($sql) or die ("Failed rereading after insert");
$row = mysql_fetch_array($result); // Extract the record
This repopulates the screen and lets the user continue entering more
data. The next time "Save" is clicked, the logic senses the existence
of a State File Number and the Update logic is called instead on
Insert. Works great until the Refresh button comes into play.
I have tried using session variables to indicate that a record has
been inserted, but haven't got it to work quite right.
Is there a way to detect that the Refresh button has been clicked?
That seems to me to be the best solution.
Thanks for all the help!
"Mark" <hi***********@yahoo.com> wrote in message
news:5e**************************@posting.google.c om... Thanks for all the helpful suggestions. The problem with the redirect (Header) idea is that it clears all the data from the screen. What I want is for the data to remain on the screen so the user can continue with entry. There is a great deal of data (12 screens), so it is reasonable to expect the user to save several times during the entry of a record.
As it currently exists, my InsertRecord.inc logic contains some code that rereads the record after the Insert:
// Reread the record after the POST operation // Fields on form are refreshed after the reread via HTML "Value" clauses
$sql = "SELECT * FROM rosemaster WHERE StateFileNumber = $NewSFN";
$result = mysql_query($sql) or die ("Failed rereading after insert");
$row = mysql_fetch_array($result); // Extract the record
This repopulates the screen and lets the user continue entering more data. The next time "Save" is clicked, the logic senses the existence of a State File Number and the Update logic is called instead on Insert. Works great until the Refresh button comes into play.
I have tried using session variables to indicate that a record has been inserted, but haven't got it to work quite right.
In what way is it *not working right*?
Is there a way to detect that the Refresh button has been clicked? That seems to me to be the best solution.
There is nothing in the HTTP protocol which detects the REFRESH button being
pressed. This is a browser function which simply redoes the last action
whatever it was.
--
Tony Marston http://www.tonymarston.net
"Tony Marston" <to**@NOSPAM.demon.co.uk> wrote in message news:<ch*******************@news.demon.co.uk>... "Mark" <hi***********@yahoo.com> wrote in message news:5e**************************@posting.google.c om... Thanks for all the helpful suggestions. The problem with the redirect (Header) idea is that it clears all the data from the screen. What I want is for the data to remain on the screen so the user can continue with entry. There is a great deal of data (12 screens), so it is reasonable to expect the user to save several times during the entry of a record.
As it currently exists, my InsertRecord.inc logic contains some code that rereads the record after the Insert:
// Reread the record after the POST operation // Fields on form are refreshed after the reread via HTML "Value" clauses
$sql = "SELECT * FROM rosemaster WHERE StateFileNumber = $NewSFN";
$result = mysql_query($sql) or die ("Failed rereading after insert");
$row = mysql_fetch_array($result); // Extract the record
This repopulates the screen and lets the user continue entering more data. The next time "Save" is clicked, the logic senses the existence of a State File Number and the Update logic is called instead on Insert. Works great until the Refresh button comes into play.
I have tried using session variables to indicate that a record has been inserted, but haven't got it to work quite right.
In what way is it *not working right*?
Is there a way to detect that the Refresh button has been clicked? That seems to me to be the best solution.
There is nothing in the HTTP protocol which detects the REFRESH button being pressed. This is a browser function which simply redoes the last action whatever it was.
Thanks, Tony. I'll try to explain the problem. I introduced a
session variable that contains the SFN (State File Number - unique
key) of a new record immediately after INSERT. It now looks like
this:
if (isset($_POST['cmdSubmitSave']))
{
if ($_POST[txtStateFileNumber] == "")
{
if ($_SESSION['RefreshSFN'] <> "")
{
// Reread using Session Var
$TempSFN = $_SESSION['RefreshSFN'];
$sql = "SELECT * FROM rosemaster
WHERE StateFileNumber = $TempSFN";
$result = mysql_query($sql) or die ("Failed rereading after
refresh");
$row = mysql_fetch_array($result); // Extract the record
}
else
{
include ("InsertRecord.inc"); // Add a new record
$_SESSION['RefreshSFN'] = $NewSFN; // Store for reread if Refresh
clicked
}
}
else
{
include ("UpdateRecord.inc"); // Update existing record
$_SESSION['RefreshSFN'] = ""; // Clear
}
}
This works great. If the user clicks "Save" to INSERT a new record
and then clicks Refresh, the existing record is reread and returned to
the screen with no additional copy saved.
However, the program also includes a "New" button that clears the data
from the screen. This is a Normal button, not Submit. All it does is
use VBScript to clear the data from the textboxes.
If the user enters a record and clicks "Save", the record is INSERTed
and the session var loaded with the SFN. If the user then clicks
"New", the data are cleared from the screen, but the session var
remains loaded, so that when a new record is entered and "Save"
clicked, the session var exists and the previous record returned to
the screen. Not good.
I tried to find a way to clear the session var when "New" is clicked,
but haven't found a way yet since it is not a "Submit" button. Should
I try changing it to "Submit" and add PHP code to clear the session
var? Or is there a better approach?
Thanks again!
"Mark" <hi***********@yahoo.com> wrote in message
news:5e**************************@posting.google.c om... "Tony Marston" <to**@NOSPAM.demon.co.uk> wrote in message news:<ch*******************@news.demon.co.uk>... "Mark" <hi***********@yahoo.com> wrote in message news:5e**************************@posting.google.c om... > Thanks for all the helpful suggestions. The problem with the redirect > (Header) idea is that it clears all the data from the screen. What I > want is for the data to remain on the screen so the user can continue > with entry. There is a great deal of data (12 screens), so it is > reasonable to expect the user to save several times during the entry > of a record. > > As it currently exists, my InsertRecord.inc logic contains some code > that rereads the record after the Insert: > > // Reread the record after the POST operation > // Fields on form are refreshed after the reread via HTML "Value" > clauses > > $sql = "SELECT * FROM rosemaster > WHERE StateFileNumber = $NewSFN"; > > $result = mysql_query($sql) or die ("Failed rereading after insert"); > > $row = mysql_fetch_array($result); // Extract the record > > This repopulates the screen and lets the user continue entering more > data. The next time "Save" is clicked, the logic senses the existence > of a State File Number and the Update logic is called instead on > Insert. Works great until the Refresh button comes into play. > > I have tried using session variables to indicate that a record has > been inserted, but haven't got it to work quite right.
In what way is it *not working right*?
> Is there a way to detect that the Refresh button has been clicked? > That seems to me to be the best solution.
There is nothing in the HTTP protocol which detects the REFRESH button being pressed. This is a browser function which simply redoes the last action whatever it was.
Thanks, Tony. I'll try to explain the problem. I introduced a session variable that contains the SFN (State File Number - unique key) of a new record immediately after INSERT. It now looks like this:
if (isset($_POST['cmdSubmitSave'])) { if ($_POST[txtStateFileNumber] == "") { if ($_SESSION['RefreshSFN'] <> "") { // Reread using Session Var
$TempSFN = $_SESSION['RefreshSFN'];
$sql = "SELECT * FROM rosemaster WHERE StateFileNumber = $TempSFN";
$result = mysql_query($sql) or die ("Failed rereading after refresh");
$row = mysql_fetch_array($result); // Extract the record
} else { include ("InsertRecord.inc"); // Add a new record $_SESSION['RefreshSFN'] = $NewSFN; // Store for reread if Refresh clicked } } else { include ("UpdateRecord.inc"); // Update existing record $_SESSION['RefreshSFN'] = ""; // Clear } }
This works great. If the user clicks "Save" to INSERT a new record and then clicks Refresh, the existing record is reread and returned to the screen with no additional copy saved.
However, the program also includes a "New" button that clears the data from the screen. This is a Normal button, not Submit. All it does is use VBScript to clear the data from the textboxes.
If the user enters a record and clicks "Save", the record is INSERTed and the session var loaded with the SFN. If the user then clicks "New", the data are cleared from the screen, but the session var remains loaded, so that when a new record is entered and "Save" clicked, the session var exists and the previous record returned to the screen. Not good.
I tried to find a way to clear the session var when "New" is clicked, but haven't found a way yet since it is not a "Submit" button. Should I try changing it to "Submit" and add PHP code to clear the session var? Or is there a better approach?
Thanks again!
You cannot clear a session var by running vbscript/javascript on the client
as all session data is held on the server. You should have a CLEAR button
which POSTs back to the web server (and PHP) so that the server-side script
can clear the session data and send back an empty screen.
Another way would be not to bother with storing RefeshSFN on the server but
rely on the contents of txtStateFileNumber in the $_POST array. Your
existing NEW button should empty this variable so that your PHP script can
see whether to create a new record or update an exiting one.
I personally don't waste my time with any client-side scripting as it may be
turned off or incompatible with the client's browser.
HTH.
--
Tony Marston http://www.tonymarston.net This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Bri |
last post by:
Greetings,
I'm having a very strange problem in an AC97 MDB with ODBC Linked tables
to SQL Server 7. The table has an Identity field and a Timestamp field.
The problem is that when a new record...
|
by: todholt |
last post by:
Hello,
I am trying to bypass a form's automatic update, and instead call a
stored procedure in sql server. I am using continuous forms. The
problem I am having is with returning to the next...
|
by: swingingming |
last post by:
Hi, If I have a primary key, say orderID, after I refreshed the form,
how can i get to that record via VBA.
Thanks.
|
by: Br |
last post by:
First issue:
When using ADPs you no longer have the ability to issue a me.refresh to
save the current record on a form (the me.refresh does a requery in an
ADP).
We usually do this before...
|
by: sara |
last post by:
I have a simple app, and I'm trying to add Orders.
I have tblOrders and tblOrderDetails.
First, the user selects the customer, then "orders", "new Order"
The frmNewOrder simply assures the...
|
by: Catriona |
last post by:
I am developing an Access application where users insert bill records
for an electricity account by clicking on a new button. The required
workflow is
1) New button clicked
2) New record appears...
|
by: dzulai |
last post by:
i have a continuous subform and its AllowAdditons and AllowEdits property are set to false. A command button("Add") in my main form sets both properties to True, enabling the New Record to appear. My...
|
by: AppDev63 |
last post by:
I've been struggling with a form. On the left side of the form I've got data from a table of invoices, and on the right side I've got a combo box with data from a table of payments. The user scrolls...
|
by: trixxnixon |
last post by:
i have a form that is being designed to pend requests in a requests database.
the pend form is opened from an update form used by an employee to enter updates. when the pend form is updated, the...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
| |