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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Removing an item

 



Samoth
Deleted

Jan 24, 2001, 1:16 PM

Post #1 of 4 (294 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
?action=RemoveItem&number=1
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:
action=RemoveItem&number=

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'};
splice(@ToBeModified,$KillNumber,1,());

&SetCookies('cart',@ToBeModified);

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";
$RemoveNumber++;
$tobeadded = $ToBeModified;
} #end foreach
&TotalIt;

print "<tr><td colspan=3 align=right>Total:</td><td><b>\ Kr.";
printf("%.2f", $TheTotal);
print "</b></td></tr>\n";
print "</table>\n";
&CheckOut;
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";
exit;
} #end else
} #end sub



kencl
User

Jan 25, 2001, 2:08 AM

Post #2 of 4 (285 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!


zanardi
journeyman

Jan 25, 2001, 2:39 PM

Post #3 of 4 (273 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

My BBS


Samoth
Deleted

Jan 25, 2001, 2:53 PM

Post #4 of 4 (272 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:
http://lasiodora-parahybana.com/demo/

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