Right. I store mine in the same db, and it gets inserted with the other data
from the form. Before inserting, the script does a quick query, selecting
all rows where the unique_id is equal to the current ID. since a new one is
generated for each submit click, the answer will be zero on a proper insert.
On a reload, the answer (mysql_affected_rows) will be 1, so you exit the
script at that point. I also check to make sure the required fields are not
blank before inserting, so that handles the problem of inserting a blank
record if the user clicks twice.

anyway, it works... you can click and click and click all you want, reload
until you're blue in the face, and you'll only get one proper insert. better
yet, not a word of javascript was involved. :)

"Jonathan Hilgeman" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED].;
> This is another good idea. When reloading the page, have the script
generate
> that unique ID, store it in a separate table AND  put it in a hidden
input.
> When the user submits, the database checks to see if the unique ID is in
the
> database, and if so, the ID is deleted from the database, and the order is
> processed. On subsequent clicks, the unique ID would not be found in that
> database table so the query would fail with a message ("You have clicked
> more than once") or something like that, and the person could check the
> status of an order identified by that unique ID.
>
> - Jonathan
>
> -----Original Message-----
> From: Aron Pilhofer [mailto:[EMAIL PROTECTED]]
> Sent: Monday, March 04, 2002 9:51 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP-DB] Tutorial?
>
>
> The easiest and best solution is to redirect to a new page after the
submit.
> But I have had cases where it was necessary to have the submit code and
the
> form on the same page.
>
> I agree totally with jonathan that a server-side solution is the way to
go.
> To solve the problem (avoid clicking twice and/or reloading the page) I
used
> a hidden field that generated a unique ID based, and then placed that into
a
> field that only accepts unique values. If the user reloads, the query
> fails - trap that error and you're golden.
>
>
> "Jonathan Hilgeman" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED].;
> > Hi Jennifer,
> > I'm guessing the purpose of this would be to keep people from
> > double-clicking and submitted information twice, possibly making an
> > application deduct payment twice or something important similar in
nature.
> >
> > The best way I've found of accomplishing the goal of keeping people from
> > clicking twice has three parts:
> > 1) Quickly switching the page. On the next page, have PHP write out
about
> > 300 spaces and a newline, then call the flush() function to make the
> output
> > get sent to the browser. In many cases, this will cause the browser to
> > quickly switch to the next page and display a blank page while the data
> gets
> > processed.
> >
> > 2) It's still remotely possibly to click twice even if you have part 1
in
> > place, so this is a more fool-proof method. Store your data in a
database
> > before processing it - along with a timestamp. When the person clicks
the
> > submit button twice, the program checks the database to see if there is
> the
> > same information with a very close timestamp. If so, update the
timestamp
> in
> > the database. At this point you can choose 3 paths:
> >
> > - Store the data so you can batch-process the data at a later time, once
> you
> > are sure that the visitor has left and there will be no more clicks. For
> > example, have a program that runs every 5 minutes (via cron), then have
> that
> > program check for data/orders that are at least 5 minutes old, and
process
> > them. That means that the timestamp hasn't been updated by extra clicks
in
> 5
> > minutes (and you could still have notified the visitor that their order
or
> > data request is now in line to be processed).
> >
> > - Process the data immediately. If you need to process an order
> immediately
> > and give back results, use the above method, but modify it a bit.
Instead
> of
> > just displaying notification that their order is in line to be
processed,
> > you can submit to another PHP program which sleeps for about 3-4
seconds,
> > then checks the database until there are no clicks for at least 4
seconds,
> > and THEN processes the data, and returns a value to the screen in like
4-5
> > seconds. Both of these methods have similar goals, though - Receive data
> and
> > timestamp it, Wait $Time, Check for timestamp updates, Process when
> > timestamp is $Time old.
> >
> > 3) Have a very visible notice that people should not click multiple
times,
> > or else undesirable results may occur, and we want "your" request/order
to
> > be perfect. Emphasize the request to click only once and to be patient,
> and
> > if something goes wrong, here's how to contact us.
> >
> > - Jonathan
> >
> > -----Original Message-----
> > From: Jennifer Downey [mailto:[EMAIL PROTECTED]]
> > Sent: Saturday, March 02, 2002 10:18 PM
> > To: [EMAIL PROTECTED]
> > Subject: [PHP-DB] Tutorial?
> >
> >
> > Hi all,
> >
> > Can anyone point me to a good tutorial on how to disable a submit button
> > once clicked?
> > preferably in php.
> >
> > Thanks
> > Jennifer Downey
> >
> >
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php



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

Reply via email to