I am trying to create a e commerce website but my current problem is when I add a product to my bag --> goes to bag.html where it shows the products I have selected but when I refresh the page the same items get incremented every time i refresh

I tried x.pl for selecting the page --> moves to chart.pl--> moves to mybag.html

But its fails every time i refresh my bag page the last item i added get incremented Please find the code for chart.pl below

#!/usr/bin/perl -w #chart.pl use strict; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use CGI::Session; use Apache::Session::MySQL; use DBI; use Template; use 5.010; use rightplacedb; use webdb; use Data::Dumper; $| =1; print "content-type: text/html\n\n"; my $dbh = webdb::connect() or die "Cannot connect to database $@\n"; my $cookie; my %session; my $template; my $sess_id = cookie('CUSTOMER_ID'); print "session id : $sess_id<br>"; tie %session, "Apache::Session::MySQL",$sess_id, { Handle => $dbh, LockHandle => $dbh }; my $page = param('t_shirt'); my $id = param('id'); my $price = param('price'); given ($page) { when ($page eq 'add_to_chart') { if (exists $session{$id}) { # update the quanity of the items $session{'$id'}{'price'} = $price; } else { $session{$id} = $id; $session{'$id'}{'price'} = $price; } print "<br>check the price $session{'$id'}{'price'}"; print "<br>the : $session{'item_code'}"; my $array = $session{'item_code'}; my @selected_item = @$array; push(@selected_item,$id); print "<br>before database : @selected_item<br>"; $session{'item_code'} = \@selected_item; print "<br>the : $session{'item_code'}"; my $bag_id = $session{'item_code'}; print "<br>my bag contains : @$bag_id<br>"; $template = '/home/romy/public_html/rightplace/template/src/mybag. +html'; $dbh->disconnect(); } default { $template = '/home/romy/public_html/rightplace/template/sr +c/entry.html'; } } untie(%session); my $vars = { position => $id, Brands => $price, }; my $tt = Template->new ({ INCLUDE_PATH => [ '/home/romy/public_html/rightplace/template/src/', '/home/romy/public_html/rightplace/template/lib/', ], WRAPPER => 'wrapper', ABSOLUTE => 1, RELATIVE => 1, }); $tt->process($template,$vars)|| die "Failed to execute the template $t +t->error() \n";

In reply to Unwanted CGI execution on Refreshing by romy_mathew

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.