CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Removing an item



Jan 24, 2001, 1:16 PM

Post #1 of 4 (298 views)
Removing an item Can't Post

Can anyone see if there are somthing wrong with the script beneth?

It removes an item using cookies and stuff
When you click a link it uses this action
My problem is if I have stored 3 items and delete 1 of them:
I get one of the two with an URL looking like this:

You see no number

here are the subroutine in the script that do the removing:

sub RemoveItem {

if (&GetCookies('cart')) {
(@ToBeModified) = split(/\|/, $Cookies{'cart'});
$KillNumber = $contents{'number'};


print "Content-type: text/html\n\n";
print "<html><head><title>Slettet</title></head><body bgcolor=white>Artikkelen er tatt bort<p>\n";
print "Handlekurven din inneholder:\n";
print "<table border=1><tr><td>Ant.</td><td>Artikkel</td><td>Farge</td><td>Str</td><td>Pris</td><td> </td></tr>\n";

foreach $ToBeModified (@ToBeModified) {

($quantity, $price, $item, $farge, $str) = split(/:/ , $ToBeModified);

print "<tr><td>$quantity</td><td>$item</td><td>$farge</td><td>$str</td><Td>\Kr.$price stk.</td><td><a href=$newform?action=RemoveItem\&number=$RemoveNumber>Ta bort</a></td></tr>\n";
$tobeadded = $ToBeModified;
} #end foreach

print "<tr><td colspan=3 align=right>Total:</td><td><b>\ Kr.";
printf("%.2f", $TheTotal);
print "</b></td></tr>\n";
print "</table>\n";
print "<a href=$referer>Fortsett handle</a>\n";
print "</body></html>";
} #end if
else {
print "Du m ha Artikkler i handlekurven for ta bort.\n";
print "<a href=$referer>Fortsett handle</a>\n";
} #end else
} #end sub


Jan 25, 2001, 2:08 AM

Post #2 of 4 (289 views)
Re: Removing an item [In reply to] Can't Post

In this line:

a href=$newform?action=RemoveItem\&number=$RemoveNumber>Ta bort

RemoveItem should be $RemoveItem

I don't see where your initalizing $RemoveNumber at all. If the first time you use it is in this line, then it will be empty.

>> If you can't control it, improve it, correlate it or disseminate it with PERL, it doesn't exist!


Jan 25, 2001, 2:39 PM

Post #3 of 4 (277 views)
Re: Removing an item [In reply to] Can't Post

no I dont think he wants it to be $RemoveItem, he is telling the script where he wants to go:

if ($action eq 'RemoveItem') {
... whatever ...

like that



Jan 25, 2001, 2:53 PM

Post #4 of 4 (276 views)
Re: Removing an item [In reply to] Can't Post

Thanks folx for helping me to solve this

I have an litle demo where you can see it action and see the problem.

If you go to this URL:

Try adding 3-4 times and then click the 'ta bort' (norwegian for delete' and then check the URL for the first item it displays no number.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives