Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Nihir's avatar
Level 50

Hi the value has been increment everytime when i refresh the page

Hi there, I worked on check out page and got the data using a session like this. I pass the data perfectly and retrieve it without errors, but when I refresh the page, the data is incremented. Here is my code (Controller).

        if(session()->has('user_name') || session()->has('user_id') ){
$user_name = session('user_name');
            $people = session('people');
            $total = session('total');
            $slot_price= session('slot_price');
            $slot_time= session('slot_time');
            $date= session('date');
            $month= session('month');
            $additional_product = session('additional_product');
            $baseAmount = $people * $slot_price; 
            $gstamount = (5 / 100) * $total ; //1600
            $baseAmount = $baseAmount - $gstamount;
            session()->put('gst', $gstamount);
                $addpprice = '0';
                foreach($additional_product as $product) {
                    $addpprice = $addpprice + $product['price'];
                    session()->put('total',$total + $addpprice);
                }
}

Any suggestion or solution ?

0 likes
3 replies
Snapey's avatar

don't keep adding to total

you get total from session then add the cost of each product to total then save total back in session

Please or to participate in this conversation.