#!/usr/local/bin/perl use strict; use CGI; use CGI::Carp 'fatalsToBrowser'; #remove for prod use DBI; # get form parameters my $q = new CGI; my $action = $q->param('go'); my $orderid = $q->param('orderid'); my $msg = ""; my $dbh = dbh(); # connect to db $dbh->do("SET search_path to northwind") or die; my $sql = 'SELECT a."OrderID", b."ProductName", a."UnitPrice", a."Quantity", a."Discount" FROM "Order_Details" a, "Products" b WHERE a."ProductID" = b."ProductID" AND "OrderID" = ? '; my $hr = $dbh->selectrow_hashref($sql,undef,$orderid); #change validation to suit if ( ($action eq "UPDATE") && ($orderid =~ /\d+/)) { 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"; } else { $msg = "Please complete form"; } # build html page my $style = q! body { background-color: pink ; color: #3300cc; } .container { width: 500px; clear: both; } .container input { width: 100%; clear: both;} !; # Send out the header and form print $q->header; print $q->start_html(-title=>'Order details', -style=>{ -code=>$style } ); if ( ($action eq "EDIT") && ($orderid =~ /\d+/)) { print qq!

Update Order Details for order # ?

!; print qq!
Product Name :
Unit Price :
Quantity :
Discount :

!; $msg = ""; } else { print qq!

Order Details for order # $orderid

!; print qq!
Product Name :
Unit Price :
Quantity :
Discount :

!; $msg = "Record details fetched - $sql, $orderid"; } # Standard links to the rest of the application print <<"FOOTER"; $msg
Jump to - View Employees Listing
Jump to - Add an Employee
Jump to - Edit an Employee details
Jump to - Add or update Employee Photo

Edited by Terry on July, 06 2014. FOOTER print $q->end_html; # 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; }