Jump to content

On Browser Refresh/Reload, Last CRUD Operation Being Repeated - How to reset/re-initialize that behavior?


excelmaster

Recommended Posts

Hello All,

 

I've encountered one more problem (with the first WebApp I'm building), and I have no idea how to fix it. I've tried something, but it doesn't seem to work, so I'd appreciate some help in getting it fixed.

 

Here's what's happening:

 

So after I perform an operation (let's say "ADDing a record")...the records gets added correctly, but then, if/when I press [F5] in my browser window (or click on the Refresh/Reload icon), the same input details are being used and a second identical record is being added. I believe the same thing happens for some (or perhaps all) of the other CRUD operations.

 

What do I need to do to disable that behavior?

 

The only thing I could think of is to set the $functionSelected variable to blank ("") - which I've done towards the bottom of my code (shown below) - but that doesn't seem to be doing anything...the problem persists.

if(isset($_POST['action']))

    {                        

        $functionSelected = $_POST["action"];

    }



if(isset($functionSelected)){

    switch($functionSelected){

        case "insert":

            $initialize_flag = "N";

            // Store POST(ed) user-entered values into memory variables

            $store_name = $_POST['store_name'];    

            $item_description = $_POST['item_description'];    

            $qty_pkg = $_POST['qty_pkg'];    

            $pkg_of = $_POST['pkg_of'];    

            $price = $_POST['price'];    

            $flyer_page = $_POST['flyer_page'];    

            $limited_time_sale = $_POST['limited_time_sale'];    

            $flyer_date_start = $_POST['flyer_date_start'];    

            $nos_to_purchase = $_POST['nos_to_purchase'];    

                                    

            // Setup customized query

            $sql = "INSERT INTO shoplist

                        (store_name, item_description, qty_pkg, pkg_of, price, flyer_page, limited_time_sale, flyer_date_start, nos_to_purchase, shopper1_buy_flag, shopper2_buy_flag, purchased_flag, purchase_later_flag)

                    VALUES

                        (:store_name, :item_description, :qty_pkg, :pkg_of, :price, :flyer_page, :limited_time_sale, :flyer_date_start, :nos_to_purchase, :shopper1_buy_flag, :shopper2_buy_flag, :purchased_flag, :purchase_later_flag)";



            try {

                $statement = $conn->prepare($sql);

                                    

                $statement->bindParam(':store_name', $store_name);

                $statement->bindParam(':item_description', $item_description);

                $statement->bindParam(':qty_pkg', $qty_pkg);

                $statement->bindParam(':pkg_of', $pkg_of);

                $statement->bindParam(':price', $price);

                $statement->bindParam(':flyer_page', $flyer_page);

                $statement->bindParam(':limited_time_sale', $limited_time_sale);

                $statement->bindParam(':flyer_date_start', $flyer_date_start);

                $statement->bindParam(':nos_to_purchase', $nos_to_purchase);

                $statement->bindParam(':shopper1_buy_flag', $initialize_flag);

                $statement->bindParam(':shopper2_buy_flag', $initialize_flag);

                $statement->bindParam(':purchased_flag', $initialize_flag);

                $statement->bindParam(':purchase_later_flag', $initialize_flag);                                        



                // Execute the query

                $statement->execute();                            

                $statement->closeCursor();

                $functionSelected = "";     // WILL THIS STATEMENT NOT SERVE TO INITIALIZE/RESET THE OPERATION???

                break;

            } catch (PDOException $e) {

                print "Error!: " . $e->getMessage() . "<br/>";

            }

        case "update-delete":    

            ...

            ...

            ...

Thanks.

 

Link to comment
Share on other sites

The problem is that the POST variables are still set. You'll need to redirect the browser after a successful CRUD operation. You can simply reload the current page or redirect to a new page, whichever is best for your situation. There's actually a name for this operational method, but I can't for the life of me remember what it is right now...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.