Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: How to retain a value passed from another link to a script

by poj (Priest)
on Jul 11, 2014 at 19:12 UTC ( #1093291=note: print w/ replies, xml ) Need Help??


in reply to Re^2: How to retain a value passed from another link to a script
in thread How to retain a value passed from another link to a script

Spot the parameter name difference

my $orderid = $q->param('orderid'); <input type="hidden" name="ordid" value="$hr->{'OrderID'}"/>
When you fix that this will fail (not enough bind variables)
my $sql = qq! UPDATE "Order_Details" SET "UnitPrice" = ?, "Quantity" = ?, "Discount" = ? WHERE "OrderID" = ? !; my $count = $dbh->do( $sql,undef,$orderid );
poj


Comment on Re^3: How to retain a value passed from another link to a script
Select or Download Code
Re^4: How to retain a value passed from another link to a script
by terrykhatri (Acolyte) on Jul 11, 2014 at 19:44 UTC
    Many thanks Poj, You are the only ONE :) OK you are right the update is failing I changed the code though :
    if ( ($action eq "UPDATE") && ($orderid =~ /\d+/)) { my @data=(); my @fields = qw!unitprice quantity discount !; for my $f (@fields){ push @data,$q->param($f) || '' ; } push @data,$orderid; my $sql = qq! UPDATE "Order_Details" SET "UnitPrice" = ?, "Quantity" = ?, "Discount" = ? WHERE "OrderID" = ? !; my $count = $dbh->do( $sql,undef,$orderid ); $msg = "$count Record updated - $sql, $orderid";
    Please help !!!
      my $count = $dbh->do( $sql,undef,@data ); # not $orderid
      poj
Re^4: How to retain a value passed from another link to a script
by terrykhatri (Acolyte) on Jul 11, 2014 at 20:10 UTC
    Many many many thank Poj, you are amazing !!! I have one more queston to ask and that is pagination, I need to paginate a form which has too many records, I have been searching google but I DONT quite understand how to implement it, if you can help me that will be great !!! Rgds. Terry
Re^4: How to retain a value passed from another link to a script
by terrykhatri (Acolyte) on Jul 11, 2014 at 20:20 UTC
    Here is the script that needs pagination :
    #!/usr/local/bin/perl use DBI; use CGI; use strict; use HTML::Template; my $CGI = CGI->new(); my $dbh = dbh(); # connect to db $dbh->do("SET search_path to northwind") or die; # grab the stuff from the database my $sql = qq!SELECT a."OrderID", b."CompanyName" AS "CustomerName", c."FirstName"::text || ' ' ||c."LastName"::text AS "E +mployeeName", a."OrderDate", a."RequiredDate", a."ShippedDate", d." +CompanyName" AS "ShipVia", a."Freight", a."ShipName", a."ShipAddress", a."ShipCi +ty", a."ShipRegion", a."ShipPostalCode", a."ShipCountry" FROM "Orders" a, "Customers" b, "Employees" c, "Shippers" +d WHERE a."CustomerID" = b."CustomerID" AND a."EmployeeID" = c."EmployeeID" AND a."ShipVia" = d."ShipperID" ORDER BY 1 !; my $sth = $dbh->prepare($sql); $sth->execute(); # prepare a data structure for HTML::Template my $rows; push @{$rows}, $_ while $_ = $sth->fetchrow_hashref(); # instantiate the template and substitute the values my $template = HTML::Template->new(filename => 'Orders.tmpl'); $template->param(ROWS => $rows); print $CGI->header(); print $template->output(); $dbh->disconnect(); # connect to database sub dbh { my $dsn = 'DBI:Pg:dbname=northwind;host=localhost'; my $user = 'postgres'; my $pwd = 'postgres'; my $dbh = DBI -> connect($dsn,$user,$pwd,{'RaiseError' => 1}); return $dbh; }
    If you need the template code used in this script I will post it. Many thank !!!

      This isn't a code writing service. It looks as thought you've just outsourced your task to several forums

Re^4: How to retain a value passed from another link to a script
by terrykhatri (Acolyte) on Jul 11, 2014 at 20:31 UTC
    Hi Marto, I have tried to implement it by googling through various examples but no example is working or fitting to my situation, I am learning by getting the code, the help provided to me by your monks specially Poj has helped me do so many other webpages which you don't know, once I am done with this project I am going study all the links given to me in this forum I promise OK !! Thanks for putting up with me !!
      once I am done with this project I am going study all the links given to me in this forum I promise OK !!
      Wrong approach. Try to use these links to solve yourself your current problems, and ask for help when, despite having used these links and tried to code solutions, you get into a dead end. Asking other people to solve the problems for you will not make you improving, which does by no way mean that you should not be asking for help (sometimes we all need help from others, nobody was born with the Full and True Knowledge), it will only possibly solve your immediate problem. But really trying hard to solve yourself your problems will really get you a long way forward, even if you occasionally have to ask for some help when stumbling on some road blocks.

      You're never gonna get anywhere if you hope to get away from hard work by asking others to do it for you. Please understand me well, I am not chastising you, nor trying to teach you a lesson, I am only trying to help you going forward and becoming a good problem solver, and I believe many monks here, including myself, make their living from having become good at problem solving (whether it is in the Perl language, some other language or some other technology), and the only way to get good at problem solving is to work hard solving problems. It may look very challenging at first, but it is in fine very rewarding.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1093291]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (16)
As of 2014-12-22 13:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (118 votes), past polls