Re: [PHP] Refresh (F5) adds another SQL record.

2008-12-08 Thread Bhupendra Patel
If the user hits the back button and then the forward, it sometimes
resubmits the form.
This is why i initiated the session and ended it at the end of the data
processing page. If they happen to press forward, or back, it will still not
initiate the form unless they have actually visitied and submitted the form.

2008/12/7 Ashley Sheridan [EMAIL PROTECTED]

 On Sun, 2008-12-07 at 16:44 +, Bhupendra Patel wrote:
  I've found a way that works for me.
 
  Using the START SESSION on the initial form, e.g.
  ?php
  session_start();
  // store session data
  $_SESSION['form'] = 1;
  ?
 
  and the using the code below in the processing form.
 
  You can do a check if the user has already submitted the from by the
 initial
  session that starts then he/she is on the submitting form. If it is
 already
  set it can continue, else stop and redirect.
  MAKE SURE to put the unset session at the end of the form.
 
  html
  head
titleAdd Publication/title
  /head
  body
  h1Add/h1
  ?php
  // Check session
  session_start();
  if ($_SESSION['form'] == 1)
  {
// create short variable names
$producttype=$_POST['producttype'];
$producttitle=$_POST['producttitle'];
$productdescription=$_POST['productdescription'];
$productauthor=$_POST['productauthor'];
$productlang=$_POST['productlang'];
$productprice=$_POST['productprice'];
$productstatus=$_POST['productstatus'];
$productimg=$_POST['productimg'];
  }
  else
  {
echo 'Go back and complete the form';
echo header('Location: insertpublication.php');
exit;
  }
  // End session checking
 
if (!$producttype || !$producttitle || !$productauthor || !$productlang
 ||
  !$productprice || !$productstatus)
{
   echo 'You have not entered all the required details.br /'
.'Please go back and try again.';
unset($_SESSION['form']);
   exit;
}
 
@ $prodb = new mysqli('I DONT THINK SO!!!');
if (mysqli_connect_errno())
{
   echo 'Error: Could not connect to database.  Please try again
 later.';
   exit;
}
$query = INSERT into tblproductinfo
  (ProductType, ProductTitle, ProductDesc, ProdAuthor,
  ProductLang, ProductPrice, ProductStatus, ProductImg)
  VALUES
  ('.$producttype.', '.$producttitle.',
  '.$productdescription.', '.$productauthor.', '.$productlang.',
  '.$productprice.', '.$productstatus.',
 '.$productimg.');
 
$result = $prodb-query($query);
if ($result)
echo  $prodb-affected_rows.' book inserted into database.';
 
$queryshow = 
  SELECT
  tblproductinfo.ProductID,
  tblproductinfo.ProductTitle,
  tblproductinfo.ProductDesc,
  tblproductinfo.ProductPrice,
  tblproductinfo.ProductTQty,
  tblproductinfo.ProductImg,
  tblauthor.AuthorName,
  tblproductlang.ProductLang,
  tblproducttype.ProductType,
  tblproductstatus.ProductStatus
  FROM
  tblproductinfo
  Inner Join tblproductstatus ON tblproductinfo.ProductStatus =
  tblproductstatus.ProductStatusID
  Inner Join tblproductlang ON tblproductinfo.ProductLang =
  tblproductlang.ProductLangID
  Inner Join tblauthor ON tblproductinfo.ProdAuthor =
 tblauthor.AuthorID
  Inner Join tblproducttype ON tblproductinfo.ProductType =
  tblproducttype.ProductTypeID;
$resultshow = $prodb-query($queryshow);
 
$num_results = $resultshow-num_rows;
echo '
table width=700 border=1
 tr
td
   Book ID
/td
td
   Type
/td
td
   Title
/td
td
   Description
/td
td
   Author
/td
td
   Language
/td
td
   Price
/td
td
   Status
/td
td
   Image
/td
 /tr';
for ($i=0; $i $num_results; $i++)
{
   $row = $resultshow-fetch_assoc();
   echo 'tr';
   echo 'td'.($row['ProductID']).'/td';
   echo 'td'.($row['ProductType']).'/td';
   echo 'td'.($row['ProductTitle']).'/td';
   echo 'td'.($row['ProductDesc']).'/td';
   echo 'td'.($row['AuthorName']).'/td';
   echo 'td'.($row['ProductLang']).'/td';
   echo 'td£'.($row['ProductPrice']).'/td';
   echo 'td'.($row['ProductStatus']).'/td';
   echo 'tda href=images/'.($row['ProductImg']).'Preview image
  /a/td';
   echo '/tr';
 };
echo '/table';
 
unset($_SESSION['form']);
 
$prodb-close();
  ?
  /body
  /html
 Would redirecting the user with a header() request do the job? Or,
 failing that, how about outputting a
 scriptlocation.href='foo.com'/script line?


 Ash
 www.ashleysheridan.co.uk




Re: [PHP] Refresh (F5) adds another SQL record.

2008-12-07 Thread Bhupendra Patel
I've found a way that works for me.

Using the START SESSION on the initial form, e.g.
?php
session_start();
// store session data
$_SESSION['form'] = 1;
?

and the using the code below in the processing form.

You can do a check if the user has already submitted the from by the initial
session that starts then he/she is on the submitting form. If it is already
set it can continue, else stop and redirect.
MAKE SURE to put the unset session at the end of the form.

html
head
  titleAdd Publication/title
/head
body
h1Add/h1
?php
// Check session
session_start();
if ($_SESSION['form'] == 1)
{
  // create short variable names
  $producttype=$_POST['producttype'];
  $producttitle=$_POST['producttitle'];
  $productdescription=$_POST['productdescription'];
  $productauthor=$_POST['productauthor'];
  $productlang=$_POST['productlang'];
  $productprice=$_POST['productprice'];
  $productstatus=$_POST['productstatus'];
  $productimg=$_POST['productimg'];
}
else
{
  echo 'Go back and complete the form';
  echo header('Location: insertpublication.php');
  exit;
}
// End session checking

  if (!$producttype || !$producttitle || !$productauthor || !$productlang ||
!$productprice || !$productstatus)
  {
 echo 'You have not entered all the required details.br /'
  .'Please go back and try again.';
  unset($_SESSION['form']);
 exit;
  }

  @ $prodb = new mysqli('I DONT THINK SO!!!');
  if (mysqli_connect_errno())
  {
 echo 'Error: Could not connect to database.  Please try again later.';
 exit;
  }
  $query = INSERT into tblproductinfo
(ProductType, ProductTitle, ProductDesc, ProdAuthor,
ProductLang, ProductPrice, ProductStatus, ProductImg)
VALUES
('.$producttype.', '.$producttitle.',
'.$productdescription.', '.$productauthor.', '.$productlang.',
'.$productprice.', '.$productstatus.', '.$productimg.');

  $result = $prodb-query($query);
  if ($result)
  echo  $prodb-affected_rows.' book inserted into database.';

  $queryshow = 
SELECT
tblproductinfo.ProductID,
tblproductinfo.ProductTitle,
tblproductinfo.ProductDesc,
tblproductinfo.ProductPrice,
tblproductinfo.ProductTQty,
tblproductinfo.ProductImg,
tblauthor.AuthorName,
tblproductlang.ProductLang,
tblproducttype.ProductType,
tblproductstatus.ProductStatus
FROM
tblproductinfo
Inner Join tblproductstatus ON tblproductinfo.ProductStatus =
tblproductstatus.ProductStatusID
Inner Join tblproductlang ON tblproductinfo.ProductLang =
tblproductlang.ProductLangID
Inner Join tblauthor ON tblproductinfo.ProdAuthor = tblauthor.AuthorID
Inner Join tblproducttype ON tblproductinfo.ProductType =
tblproducttype.ProductTypeID;
  $resultshow = $prodb-query($queryshow);

  $num_results = $resultshow-num_rows;
  echo '
  table width=700 border=1
   tr
  td
 Book ID
  /td
  td
 Type
  /td
  td
 Title
  /td
  td
 Description
  /td
  td
 Author
  /td
  td
 Language
  /td
  td
 Price
  /td
  td
 Status
  /td
  td
 Image
  /td
   /tr';
  for ($i=0; $i $num_results; $i++)
  {
 $row = $resultshow-fetch_assoc();
 echo 'tr';
 echo 'td'.($row['ProductID']).'/td';
 echo 'td'.($row['ProductType']).'/td';
 echo 'td'.($row['ProductTitle']).'/td';
 echo 'td'.($row['ProductDesc']).'/td';
 echo 'td'.($row['AuthorName']).'/td';
 echo 'td'.($row['ProductLang']).'/td';
 echo 'td£'.($row['ProductPrice']).'/td';
 echo 'td'.($row['ProductStatus']).'/td';
 echo 'tda href=images/'.($row['ProductImg']).'Preview image
/a/td';
 echo '/tr';
   };
  echo '/table';

  unset($_SESSION['form']);

  $prodb-close();
?
/body
/html


Re: [PHP] Refresh (F5) adds another SQL record.

2008-12-07 Thread Ashley Sheridan
On Sun, 2008-12-07 at 16:44 +, Bhupendra Patel wrote:
 I've found a way that works for me.
 
 Using the START SESSION on the initial form, e.g.
 ?php
 session_start();
 // store session data
 $_SESSION['form'] = 1;
 ?
 
 and the using the code below in the processing form.
 
 You can do a check if the user has already submitted the from by the initial
 session that starts then he/she is on the submitting form. If it is already
 set it can continue, else stop and redirect.
 MAKE SURE to put the unset session at the end of the form.
 
 html
 head
   titleAdd Publication/title
 /head
 body
 h1Add/h1
 ?php
 // Check session
 session_start();
 if ($_SESSION['form'] == 1)
 {
   // create short variable names
   $producttype=$_POST['producttype'];
   $producttitle=$_POST['producttitle'];
   $productdescription=$_POST['productdescription'];
   $productauthor=$_POST['productauthor'];
   $productlang=$_POST['productlang'];
   $productprice=$_POST['productprice'];
   $productstatus=$_POST['productstatus'];
   $productimg=$_POST['productimg'];
 }
 else
 {
   echo 'Go back and complete the form';
   echo header('Location: insertpublication.php');
   exit;
 }
 // End session checking
 
   if (!$producttype || !$producttitle || !$productauthor || !$productlang ||
 !$productprice || !$productstatus)
   {
  echo 'You have not entered all the required details.br /'
   .'Please go back and try again.';
   unset($_SESSION['form']);
  exit;
   }
 
   @ $prodb = new mysqli('I DONT THINK SO!!!');
   if (mysqli_connect_errno())
   {
  echo 'Error: Could not connect to database.  Please try again later.';
  exit;
   }
   $query = INSERT into tblproductinfo
 (ProductType, ProductTitle, ProductDesc, ProdAuthor,
 ProductLang, ProductPrice, ProductStatus, ProductImg)
 VALUES
 ('.$producttype.', '.$producttitle.',
 '.$productdescription.', '.$productauthor.', '.$productlang.',
 '.$productprice.', '.$productstatus.', '.$productimg.');
 
   $result = $prodb-query($query);
   if ($result)
   echo  $prodb-affected_rows.' book inserted into database.';
 
   $queryshow = 
 SELECT
 tblproductinfo.ProductID,
 tblproductinfo.ProductTitle,
 tblproductinfo.ProductDesc,
 tblproductinfo.ProductPrice,
 tblproductinfo.ProductTQty,
 tblproductinfo.ProductImg,
 tblauthor.AuthorName,
 tblproductlang.ProductLang,
 tblproducttype.ProductType,
 tblproductstatus.ProductStatus
 FROM
 tblproductinfo
 Inner Join tblproductstatus ON tblproductinfo.ProductStatus =
 tblproductstatus.ProductStatusID
 Inner Join tblproductlang ON tblproductinfo.ProductLang =
 tblproductlang.ProductLangID
 Inner Join tblauthor ON tblproductinfo.ProdAuthor = tblauthor.AuthorID
 Inner Join tblproducttype ON tblproductinfo.ProductType =
 tblproducttype.ProductTypeID;
   $resultshow = $prodb-query($queryshow);
 
   $num_results = $resultshow-num_rows;
   echo '
   table width=700 border=1
tr
   td
  Book ID
   /td
   td
  Type
   /td
   td
  Title
   /td
   td
  Description
   /td
   td
  Author
   /td
   td
  Language
   /td
   td
  Price
   /td
   td
  Status
   /td
   td
  Image
   /td
/tr';
   for ($i=0; $i $num_results; $i++)
   {
  $row = $resultshow-fetch_assoc();
  echo 'tr';
  echo 'td'.($row['ProductID']).'/td';
  echo 'td'.($row['ProductType']).'/td';
  echo 'td'.($row['ProductTitle']).'/td';
  echo 'td'.($row['ProductDesc']).'/td';
  echo 'td'.($row['AuthorName']).'/td';
  echo 'td'.($row['ProductLang']).'/td';
  echo 'td£'.($row['ProductPrice']).'/td';
  echo 'td'.($row['ProductStatus']).'/td';
  echo 'tda href=images/'.($row['ProductImg']).'Preview image
 /a/td';
  echo '/tr';
};
   echo '/table';
 
   unset($_SESSION['form']);
 
   $prodb-close();
 ?
 /body
 /html
Would redirecting the user with a header() request do the job? Or,
failing that, how about outputting a
scriptlocation.href='foo.com'/script line?


Ash
www.ashleysheridan.co.uk


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Refresh (F5) adds another SQL record.

2005-05-19 Thread Satyam

Marek Kilimajer [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Robert Meyer wrote:
 Hello,

 Scenario:
 1) User is presented a blank form.
 2) User fills in form.
 3) User submits form.
 4) Record is added to database.
 5) Back to 1).

 Go really back to 1) - use redirect. After the record is added to the 
 database, use something like:
 header('Location: http://yourserver.com/form.php');
 exit;


Or, in general, redirect to any page as soon as you made the insert.  It can 
be back to the begining or to a confirmation page, so the user gets a 
feedback of what has just been done.  The point is, don't show the 
confirmation or the new input form right in the same page as you did the 
insert, redirect to it in some way.

I use to process my data in a single form per operation.  I make each page 
like this:

if ($_REQUEST['confirm'] == 'true') {
// show the confirmation of the last operation
}
if ($_REQUEST['submit'] == 'Save') {
// do the insert here
header('Location: http://yourserver.com/form.php?confirm=true');
}

// here, show the input form which will show either for the first time or 
after the confirmation
// which ends with:
input type=submit name=submit value=Save /
/form

You might add to the redirect header some more arguments to be more explicit 
about what is it that you are confirming.  Anyway, the point is that the 
browser will store the redirected-to address with all its arguments, not the 
one with the form data, so, a refresh will give you the confirmation page, 
not the insert one.

Satyam



 All is fine to here.
 6) User clicks refresh.
 7) Another record is added, same data except auto-increment field.
 How do I prevent these last two steps, or at least prevent a record
 from being added when refresh is clicked?

 You should see a message from your browser that data is being reposted. 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Refresh (F5) adds another SQL record.

2005-05-19 Thread Satyam
Aren't we oversimplifying the issue assuming that the records inserted 
cannot have everything duplicated but the autoincrement field?

If you are taking an order and the customer says 'hey, add another of this', 
with the code below the system will reject it because it assumes that it is 
a refresh and not a new addition to the order.

You are in the supermarket line and the teller is scaning your purchase for 
the barcodes.  You wouldn't be able to buy more than one of each! (I know 
that you wouldn't use a browser in that environment, but for the purpose of 
the database analysis, it just shows the point)

NO, some tables do have records which are basically duplicate of one another 
except for the autoincrement field, and those cannot be checked this way.

And, besides, as mentioned elsewhere in this thread (myself included) there 
are easier ways which do not even involve database access.

Satyam

Marcus Joyce [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Why dont you check that data isnt being duplicated?

 $query = SELECT auto_col FROM table where col1 = $var1  col2 = $var 
 3.;
 $call_query = mysql_query($query,...
 $query_data = mysql_assoc($call_query);

 if(!$query_data) { do form }

 else echo information already exists in database;


 Pierce

 Robert Meyer wrote:

Hello,

Scenario:
1) User is presented a blank form.
2) User fills in form.
3) User submits form.
4) Record is added to database.
5) Back to 1).
All is fine to here.
6) User clicks refresh.
7) Another record is added, same data except auto-increment field.
How do I prevent these last two steps, or at least prevent a record
from being added when refresh is clicked?

Regards,

Robert
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Refresh (F5) adds another SQL record.

2005-05-19 Thread Satyam
I did something pretty similar to this but not with an MD5 hash.  I used a 
table which had just two fields, one autoincrement and another one a 
boolean.  When doing a form, I added one record to this table and the ID I 
got from it is the one I sent in the form, the other field served to 
indicate that the ID had been used, as you mention.  Later on I read about 
redirecting out of the update page, as Marek Kilimajer replied above and 
never bothered to do it again.

Satyam


Richard Lynch [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 On Tue, May 17, 2005 2:24 pm, Robert Meyer said:
 Hello,

 Scenario:
 1) User is presented a blank form.

 with an MD5 hash which is stored in the database as fresh

 2) User fills in form.
 3) User submits form.
 4) Record is added to database.

 That particular MD5 has is marked as used

 5) Back to 1).
 All is fine to here.
 6) User clicks refresh.
 7) Another record is added, same data except auto-increment field.
 How do I prevent these last two steps, or at least prevent a record
 from being added when refresh is clicked?

 The used MD5 hash tells you they are re-submitting the exact same form.

 Now, if the real problem is that the user has a fresh new form, and fills
 in the same data again by hand, then there are only two possibilities:

 1. In the real world, they actually NEED two of the same thing in the
 database, and your application should allow it.

 2. In the real world, users are likely to lose track of where they are in
 their data entry, and you need to provide them the context to help avoid
 that. When you go back to 1) present a message like added blah blah blah
 at the top of the screen.  Now they *KNOW* they just did blah blah blah,
 and can move on to blah blah bleh.  Data entry is a sucky job.  Make it
 nicer for them, eh?  You STILL need to code for the dual entry, and do
 something intelligent when they mess up, but you can improve efficiency
 and decrease errors (where 2 not-quite-the-same-but-really-are-the-same
 entries pass your tests) if you make your application nicer to the user.

 -- 
 Like Music?
 http://l-i-e.com/artists.htm 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Refresh (F5) adds another SQL record.

2005-05-18 Thread Richard Lynch
On Tue, May 17, 2005 2:24 pm, Robert Meyer said:
 Hello,

 Scenario:
 1) User is presented a blank form.

with an MD5 hash which is stored in the database as fresh

 2) User fills in form.
 3) User submits form.
 4) Record is added to database.

That particular MD5 has is marked as used

 5) Back to 1).
 All is fine to here.
 6) User clicks refresh.
 7) Another record is added, same data except auto-increment field.
 How do I prevent these last two steps, or at least prevent a record
 from being added when refresh is clicked?

The used MD5 hash tells you they are re-submitting the exact same form.

Now, if the real problem is that the user has a fresh new form, and fills
in the same data again by hand, then there are only two possibilities:

1. In the real world, they actually NEED two of the same thing in the
database, and your application should allow it.

2. In the real world, users are likely to lose track of where they are in
their data entry, and you need to provide them the context to help avoid
that. When you go back to 1) present a message like added blah blah blah
at the top of the screen.  Now they *KNOW* they just did blah blah blah,
and can move on to blah blah bleh.  Data entry is a sucky job.  Make it
nicer for them, eh?  You STILL need to code for the dual entry, and do
something intelligent when they mess up, but you can improve efficiency
and decrease errors (where 2 not-quite-the-same-but-really-are-the-same
entries pass your tests) if you make your application nicer to the user.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Refresh (F5) adds another SQL record.

2005-05-18 Thread Mukasa Assey Alfred
Force a reload of the document after step (4), you may use javascript to 
reload this document, ie...
After step (4) add this line...

print scriptdocument.location.href='your-document-url';/script;
Assey.
On Tue, 17 May 2005, Robert Meyer wrote:
Hello,
Scenario:
1) User is presented a blank form.
2) User fills in form.
3) User submits form.
4) Record is added to database.
5) Back to 1).
All is fine to here.
6) User clicks refresh.
7) Another record is added, same data except auto-increment field.
How do I prevent these last two steps, or at least prevent a record
from being added when refresh is clicked?
Regards,
Robert
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Refresh (F5) adds another SQL record.

2005-05-18 Thread Mukasa Assey Alfred

On Tue, 17 May 2005, Robert Meyer wrote:
As a last resort, I may have to do that, but that is by no means the
preferred method.  I want to keep database access to a minimum.
I thought by this time this problem would have had a standard solution.  It
would be nice if PHP had a function like refreshed() so one could do ... if
(!refreshed()) { ... } ..., but I guess not.
PHP is a server-side programming language, the problem you are facing is a 
client-side problem. PHP thus would not be able to do browser refreshes! 
sorry! Unless of course you have a PHP enabled browser :-)

Your browser caches the information sent from the 
form and so long as the page is not reloaded..., the variables are still 
set and submition of data may continue indefinately.

Two options,
You may use the php header() funtion for redirection,
or
Resort to a client-side reload using a scripting language like 
javascript..., document.location.href='';

Assey.
Thanks for your input.
Regards,
Robert
Marcus Joyce [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Why dont you check that data isnt being duplicated?
$query = SELECT auto_col FROM table where col1 = $var1  col2 = $var
3.;
$call_query = mysql_query($query,...
$query_data = mysql_assoc($call_query);
if(!$query_data) { do form }
else echo information already exists in database;
Pierce
Robert Meyer wrote:
Hello,
Scenario:
1) User is presented a blank form.
2) User fills in form.
3) User submits form.
4) Record is added to database.
5) Back to 1).
All is fine to here.
6) User clicks refresh.
7) Another record is added, same data except auto-increment field.
How do I prevent these last two steps, or at least prevent a record
from being added when refresh is clicked?
Regards,
Robert
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Refresh (F5) adds another SQL record.

2005-05-18 Thread M. Sokolewicz
Next time, Mukasa, try reading... Robert clearly states that he'd like a 
PHP function which TELLS him if the page has been refreshed or not 
(thus, resent). There are headers sent out that indicate this, and 
thus a function like refreshed() would be a shortcut to getting to know 
if it has.

He doesn't ask to FORCE a refresh, or to even execute PHP in a browser 
(what? how did you get to this...??)

Mukasa Assey Alfred wrote:

On Tue, 17 May 2005, Robert Meyer wrote:
As a last resort, I may have to do that, but that is by no means the
preferred method.  I want to keep database access to a minimum.
I thought by this time this problem would have had a standard 
solution.  It
would be nice if PHP had a function like refreshed() so one could do 
... if
(!refreshed()) { ... } ..., but I guess not.

PHP is a server-side programming language, the problem you are facing is 
a client-side problem. PHP thus would not be able to do browser 
refreshes! sorry! Unless of course you have a PHP enabled browser :-)

Your browser caches the information sent from the form and so long as 
the page is not reloaded..., the variables are still set and submition 
of data may continue indefinately.

Two options,
You may use the php header() funtion for redirection,
or
Resort to a client-side reload using a scripting language like 
javascript..., document.location.href='';

Assey.
Thanks for your input.
Regards,
Robert
Marcus Joyce [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Why dont you check that data isnt being duplicated?
$query = SELECT auto_col FROM table where col1 = $var1  col2 = $var
3.;
$call_query = mysql_query($query,...
$query_data = mysql_assoc($call_query);
if(!$query_data) { do form }
else echo information already exists in database;
Pierce
Robert Meyer wrote:
Hello,
Scenario:
1) User is presented a blank form.
2) User fills in form.
3) User submits form.
4) Record is added to database.
5) Back to 1).
All is fine to here.
6) User clicks refresh.
7) Another record is added, same data except auto-increment field.
How do I prevent these last two steps, or at least prevent a record
from being added when refresh is clicked?
Regards,
Robert
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Refresh (F5) adds another SQL record.

2005-05-18 Thread Marek Kilimajer
Robert Meyer wrote:
Marek Kilimajer [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

Robert Meyer wrote:
Hello,
Scenario:
1) User is presented a blank form.
2) User fills in form.
3) User submits form.
4) Record is added to database.
5) Back to 1).
Go really back to 1) - use redirect. After the record is added to the 
database, use something like:
header('Location: http://yourserver.com/form.php');
exit;

Does this work for all browsers?
yes.

All is fine to here.
6) User clicks refresh.
7) Another record is added, same data except auto-increment field.
How do I prevent these last two steps, or at least prevent a record
from being added when refresh is clicked?
You should see a message from your browser that data is being reposted.

I looked for such a message and the only thing I can find is as follows:
1) _SERVER['HTTP_ACCEPT'] and _ENV['HTTP_ACCEPT'] and change to */*, but I 
don't know if that is the case for all browsers, do you know?

2) _SERVER['REDIRECT_UNIQUE_ID'] and _ENV['REDIRECT_UNIQUE_ID'], 
_SERVER['REMOTE_PORT'] and _ENV['REMOTE_PORT'], _SERVER['UNIQUE_ID'] and 
_ENV['UNIQUE_ID'] change, but I don't think the values are predictable, 
especially between browsers.

Do you know of a specific message to look for and is that message the same 
for all browsers? 
that's a message the user (using the browser) gets from the browser. 
Unless you use GET method, but you should really use POST method for 
forms that change state on the server.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Refresh (F5) adds another SQL record.

2005-05-18 Thread Mukasa Assey Alfred
Sorry for that., i miss read that.. sorry, thought he wanted a php 
function to 
refresh the browser.

Assey.
On Wed, 18 May 2005, M. Sokolewicz wrote:
Next time, Mukasa, try reading... Robert clearly states that he'd like a PHP 
function which TELLS him if the page has been refreshed or not (thus, 
resent). There are headers sent out that indicate this, and thus a function 
like refreshed() would be a shortcut to getting to know if it has.

He doesn't ask to FORCE a refresh, or to even execute PHP in a browser (what? 
how did you get to this...??)

Mukasa Assey Alfred wrote:

On Tue, 17 May 2005, Robert Meyer wrote:
As a last resort, I may have to do that, but that is by no means the
preferred method.  I want to keep database access to a minimum.
I thought by this time this problem would have had a standard solution. 
It
would be nice if PHP had a function like refreshed() so one could do ... 
if
(!refreshed()) { ... } ..., but I guess not.

PHP is a server-side programming language, the problem you are facing is a 
client-side problem. PHP thus would not be able to do browser refreshes! 
sorry! Unless of course you have a PHP enabled browser :-)

Your browser caches the information sent from the form and so long as the 
page is not reloaded..., the variables are still set and submition of data 
may continue indefinately.

Two options,
You may use the php header() funtion for redirection,
or
Resort to a client-side reload using a scripting language like 
javascript..., document.location.href='';

Assey.
Thanks for your input.
Regards,
Robert
Marcus Joyce [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Why dont you check that data isnt being duplicated?
$query = SELECT auto_col FROM table where col1 = $var1  col2 = $var
3.;
$call_query = mysql_query($query,...
$query_data = mysql_assoc($call_query);
if(!$query_data) { do form }
else echo information already exists in database;
Pierce
Robert Meyer wrote:
Hello,
Scenario:
1) User is presented a blank form.
2) User fills in form.
3) User submits form.
4) Record is added to database.
5) Back to 1).
All is fine to here.
6) User clicks refresh.
7) Another record is added, same data except auto-increment field.
How do I prevent these last two steps, or at least prevent a record
from being added when refresh is clicked?
Regards,
Robert
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Refresh (F5) adds another SQL record.

2005-05-17 Thread Jay Blanchard
[snip]
6) User clicks refresh.
7) Another record is added, same data except auto-increment field.
How do I prevent these last two steps, or at least prevent a record
from being added when refresh is clicked?
[/snip]

Test for the existence (SELECT statement with the variables therein) of
the record even on the first try, if it exists, do not add (ever again),
if it does not exist do the insert

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Refresh (F5) adds another SQL record.

2005-05-17 Thread Marek Kilimajer
Robert Meyer wrote:
Hello,
Scenario:
1) User is presented a blank form.
2) User fills in form.
3) User submits form.
4) Record is added to database.
5) Back to 1).
Go really back to 1) - use redirect. After the record is added to the 
database, use something like:
header('Location: http://yourserver.com/form.php');
exit;

All is fine to here.
6) User clicks refresh.
7) Another record is added, same data except auto-increment field.
How do I prevent these last two steps, or at least prevent a record
from being added when refresh is clicked?
You should see a message from your browser that data is being reposted.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Refresh (F5) adds another SQL record.

2005-05-17 Thread Marcus Joyce
Why dont you check that data isnt being duplicated?
$query = SELECT auto_col FROM table where col1 = $var1  col2 = $var 
3.;
$call_query = mysql_query($query,...
$query_data = mysql_assoc($call_query);

if(!$query_data) { do form }
else echo information already exists in database;
Pierce
Robert Meyer wrote:
Hello,
Scenario:
1) User is presented a blank form.
2) User fills in form.
3) User submits form.
4) Record is added to database.
5) Back to 1).
All is fine to here.
6) User clicks refresh.
7) Another record is added, same data except auto-increment field.
How do I prevent these last two steps, or at least prevent a record
from being added when refresh is clicked?
Regards,
Robert 

 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Refresh (F5) adds another SQL record.

2005-05-17 Thread Robert Meyer

Marek Kilimajer [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Robert Meyer wrote:
 Hello,

 Scenario:
 1) User is presented a blank form.
 2) User fills in form.
 3) User submits form.
 4) Record is added to database.
 5) Back to 1).

 Go really back to 1) - use redirect. After the record is added to the 
 database, use something like:
 header('Location: http://yourserver.com/form.php');
 exit;

Does this work for all browsers?

 All is fine to here.
 6) User clicks refresh.
 7) Another record is added, same data except auto-increment field.
 How do I prevent these last two steps, or at least prevent a record
 from being added when refresh is clicked?

 You should see a message from your browser that data is being reposted.

I looked for such a message and the only thing I can find is as follows:

1) _SERVER['HTTP_ACCEPT'] and _ENV['HTTP_ACCEPT'] and change to */*, but I 
don't know if that is the case for all browsers, do you know?

2) _SERVER['REDIRECT_UNIQUE_ID'] and _ENV['REDIRECT_UNIQUE_ID'], 
_SERVER['REMOTE_PORT'] and _ENV['REMOTE_PORT'], _SERVER['UNIQUE_ID'] and 
_ENV['UNIQUE_ID'] change, but I don't think the values are predictable, 
especially between browsers.

Do you know of a specific message to look for and is that message the same 
for all browsers? 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Refresh (F5) adds another SQL record.

2005-05-17 Thread Robert Meyer
As a last resort, I may have to do that, but that is by no means the 
preferred method.  I want to keep database access to a minimum.

I thought by this time this problem would have had a standard solution.  It 
would be nice if PHP had a function like refreshed() so one could do ... if 
(!refreshed()) { ... } ..., but I guess not.

Thanks for your input.

Regards,

Robert

Marcus Joyce [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Why dont you check that data isnt being duplicated?

 $query = SELECT auto_col FROM table where col1 = $var1  col2 = $var 
 3.;
 $call_query = mysql_query($query,...
 $query_data = mysql_assoc($call_query);

 if(!$query_data) { do form }

 else echo information already exists in database;


 Pierce

 Robert Meyer wrote:

Hello,

Scenario:
1) User is presented a blank form.
2) User fills in form.
3) User submits form.
4) Record is added to database.
5) Back to 1).
All is fine to here.
6) User clicks refresh.
7) Another record is added, same data except auto-increment field.
How do I prevent these last two steps, or at least prevent a record
from being added when refresh is clicked?

Regards,

Robert
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php