Re: [phplib] Clearing form variables From: Davor Cengija (davor <email protected>)
Date: 09/15/00

On Thu, 14 Sep 2000, Michael J. Huber wrote:

>I have a page containing a form for creating new users and updating
>existing ones. When the 'create' or 'update' buttons are pressed the
>form posts to itself, check $HTTP_POST_VARS for update or create and
>executes the necessary mysql commands.
>
>If the page is reloaded after an update, 'update' seems to still be set
>and the page trys to update the user again causing an error. How can I
>unset or delete the update or create form variable after it has been
>used?

        Similar to the shopping cart problem discussed so many times.
        You cannot force the user agent to 'forget' the POST values
        after the Reload button is clicked. Maybe the best way to
        solve your problem is to separate the form and the
        create/update script and to introduce 'failed/succeeded'
        script.

## -- form
<form action="update_create.php" method="POST">
...
</form>

## -- update/create
<?php
        // check for validity etc
        if($ok) {
                // write new entry
                header("success.php?id=$id"); // <<<---- this is important
        }
        else {
                // failed
                header("form.php?id=$id"); // or error.php or whatever
        }
?>

        The important thing to notice is the 'header()' function which
        forwards the user agent to some other page which doen not know
        anything about the POSTed vars, and the user can click
        'Reload' as many times as he/she wants, without interferring
        with the database.

-- 
Davor Cengija
davor <email protected>
http://www.croart.com

--------------------------------------------------------------------- To unsubscribe, e-mail: phplib-unsubscribe <email protected> For additional commands, e-mail: phplib-help <email protected>