webstudioro has asked for the wisdom of the Perl Monks concerning the following question:

Hy friends!
I have one problem and i want help, please.
The problem in this script is in "sub add". I do not why when set the cookie don't write (in cookie)
$idCumparator:$denumire:$pret:$idAfiliat with : . When the cookie it's set, my line it's with ascii code
%3A . Why? I want to write set the cookie $idCumparator:$denumire:$pret:$idAfiliat with : not with ascii code . I want help. Thank you.
#!perl -w use CGI::Carp('fatalsToBrowser'); use CGI; use CGI::Cookie; use CGI; use DBI; use warnings; $query = CGI->new(); if ($query->param('product') eq "add"){ &add; } my $driver = "dbi:mysql:nx_db"; my $dbh = DBI->connect($driver, $userdb, $passworddb) or die "Error ($ +DBI:err): $DBI::errstr\n"; $statement = $dbh->prepare("SELECT id_produs, denumire, pret, url_demo +, descriere, url_download, foto, categorie FROM produse") or die "Err +or ($DBI:err): $DBI::errstr\n"; $statement->execute or die "Error ($DBI:err): $DBI::errstr\n"; print $query->header(-type=>'text/html'); while (($idProdus, $denumire, $pret, $urlDemo, $descriere, $urlDownloa +d, $foto, $catogorie) = $statement->fetchrow_array) { print <<ENDHTML; <table align=center border=0> <tr><td rowspan=3 align=center> <img src="$foto" border=0></td> <td><b>$denumire</b></td></tr> <tr><td> $descriere</td></tr> <tr><td align=right> Id product: $idProdus | Pret: $pret\$\ | <a href="$urlDemo">Try Demo!< +/a> | <a href="shop.pl?product=add&idp=$idProdus&title=$denumire&pric +e=$pret&ida=$ida">Add to Cart!</a> </td></tr></table> ENDHTML } $statement->finish; $dbh->disconnect; exit; print "Nu exista in baza de date <b>nx_db</b> nici un produs."; exit; sub add { my $idCumparator = $query->param('idc'); my $idProdus = $query->param('idp'); my $denumire = $query->param('title'); my $pret = $query->param('price'); my $idAfiliat = $query->param('ida'); my $list = "$idCumparator".":"."$denumire".":"."$pret".":"."$idAfiliat +"; my %cookie = CGI::Cookie->fetch; my $cookie = CGI::Cookie->new(-name=>$idProdus,-value=>$list); print header(-cookie=>$cookie); print "$idCumparator $idProdus $denumire $pret $idAfiliat<br>$ENV{'HTT +P_COOKIE'}"; exit; }

Replies are listed 'Best First'.
Re: Cookie shop problem
by Zaxo (Archbishop) on Sep 21, 2003 at 17:24 UTC
    perl -e'print chr(0x3A), "\n"' : $
    '%3A' is the encoded form of the separator you put in (line 49).

    After Compline,
    Zaxo

      Don't work :(, why? I wirte you code
      perl -e'print chr(0x3A), "\n"' : $

      in my header script but don't work. Please send my more informations , please. Thank you.
Re: Cookie shop problem
by idsfa (Vicar) on Sep 21, 2003 at 17:33 UTC

    What is the contents of $list? If your param's are NULL, you will set the cookie ":::", which is %3A%3A%3A when encoded. You should check the return values of those query calls ...

    ps

    $list = join(":",$idCumparator,$denumire,$pret,$idAfiliat);

    Remember, when you stare long into the abyss, you could have been home eating ice cream.