Rgds Terry#!/usr/local/bin/perl use CGI; use DBI; # Make up a pulldown menu of all the employees for reports to field $db_handle = DBI -> connect("DBI:Pg:dbname=northwind;host=localhost", +"postgres", "postgres", {'RaiseError' => 1}); $query = "select \"EmployeeID\" AS repto, \"FirstName\"::text || ' ' | +|\"LastName\"::text as name from \"Employees\""; $db_handle->do("SET search_path to northwind") or die; $qh = $db_handle->prepare($query); $qh->execute; while (@row = $qh->fetchrow) { $hh .= "<option value=$row[0]>$row[1]</option>\n"; } $qry = "select \"EmployeeID\" AS empid, \"FirstName\"::text || ' ' ||\ +"LastName\"::text as name from \"Employees\""; $qq = $db_handle->prepare($qry); $qq->execute; while (@row = $qq->fetchrow) { $tt .= "<option value=$row[0]>$row[1]</option>\n"; } # Send out the header and form print "content-type: text/html\n\n"; print <<"HEADER"; <html> <head> <title>Updte en employee record</title> <body bgcolor=pink text=#3300CC border=2 bordercolor=pink > <h1 style="color:3300CC;">Please update an employee record</h1> <style type="text/css"> .container { width: 500px; clear: both; } .container input { width: 100%; clear: both; } </style> </head> <div class="container"> <form method=POST> Select an employee to be updated and press FETCH:<select name=empid>$t +t</select><br> <input type=submit name=go value=FETCH> <input type="hidden" name="employeeid" value="$ei->{'ei'}"/> Last Name :<input name="lastname" value="$ln->{'ln'}"/><br/> First Name :<input name="firstname" value="$fn->{'fn'}"/><br/> Title :<input name="title" value="$tl->{'tl'}"/><br/> Title Of Courtesy :<input name="toc" value="$tc->{'tc'}"/><br/> Birth Date :<input name="dob" value="$bd->{'bd'}"/><br/> Hire Date :<input name="doh" value="$hd->{'hd'}"/><br/> Address :<input name="address" value="$ad->{'ad'}"/><br/> City :<input name="city" value="$ct->{'ct'}"/><br/> Region :<input name="region" value="$rg->{'rg'}"/><br/> Postal Code :<input name="pcode" value="$pc->{'pc'}"/><br/> Country :<input name="country" value="$cy->{'cy'}"/><br/> Home Phone :<input name="homephone" value="$hp->{'hp'}"/><br/> Extention :<input name="ext" value="$xt->{'xt'}"/><br/> Notes :<input name="notes" value="$nt->{'nt'}"/><br/> Reports To :<select name=repto>$hh</select><br> <input type=submit name=go value=UPDATE> </div> </form><hr> HEADER # Read form inputs read(STDIN,$buffer,$ENV{CONTENT_LENGTH}); @pairs = split(/&/,$buffer); foreach (@pairs) { ($n,$v) = split(/=/); $v =~ tr/+/ / ; $v =~ s/%(..)/pack("C",hex($1))/ge; $input{$n} = $v; } # If the form has been completed, save data entered if ($input{"go"} eq "FETCH") { $query = "SELECT \"EmployeeID\" AS ei, \"LastName\" AS ln, \"FirstName\" AS fn, \"Title\" AS tl, \"TitleOfCourtesy\" AS tc, \"BirthDate\" AS bd, \"HireDate\" AS hd, \"Address\" As ad, \"City\" AS ct, \"Region\" AS rg, \"PostalCode\" AS pc, \"Country\" AS cy, \"HomePhone\" AS hp, \"Extension\" AS xt, \"Notes\" AS nt, \"ReportsTo\" AS rt FROM \"Employees\" WHERE \"EmployeeID\"="." \'$input{empid}\'"; $ins = $db_handle->prepare($query); $ins->execute; while (@row = $ins->fetchrow) { $ei .= "<input value=$row[0]></input>\n"; $ln .= "<input value=$row[1]></input>\n"; $fn .= "<input value=$row[2]></input>\n"; $tl .= "<input value=$row[3]></input>\n"; $tc .= "<input value=$row[4]></input>\n"; $bd .= "<input value=$row[5]></input>\n"; $hd .= "<input value=$row[6]></input>\n"; $ad .= "<input value=$row[7]></input>\n"; $ct .= "<input value=$row[8]></input>\n"; $rg .= "<input value=$row[9]></input>\n"; $pc .= "<input value=$row[10]></input>\n"; $cy .= "<input value=$row[11]></input>\n"; $hp .= "<input value=$row[12]></input>\n"; $xt .= "<input value=$row[13]></input>\n"; $nt .= "<input value=$row[14]></input>\n"; $rt .= "<input value=$row[15]></input>\n"; } #$db_handle -> do($ins); $action = "Record saved - $ins"; # If no form entered, ask user to complete one } else { $action = "Please complete form"; } # If the form has been completed, save data entered if ($input{"go"} eq "UPDATE") { $query = "UPDATE \"Employees\" SET \"LastName\" = "." \'$input{lastname}\', \"FirstName\" = "." \'$input{firstname}\', \"Title\" = "." \'$input{title}\', \"TitleOfCourtesy\" = "." \'$input{toc}\', \"BirthDate\" = "." \'$input{dob}\', \"HireDate\" = "." \'$input{doh}\', \"Address\" = "." \'$input{address}\', \"City\" = "." \'$input{city}\', \"Region\" = "." \'$input{region}\', \"PostalCode\" = "." \'$input{pcode}\', \"Country\" = "." \'$input{country}\', \"HomePhone\" = "." \'$input{homephone}\', \"Extension\" = "." \'$input{ext}\', \"Notes\" = "." \'$input{notes}\', \"ReportsTo\" = "." \'$input{repto}\' WHERE \"EmployeeID\"="." \'$input{employeeid}\'"; $db_handle -> do($query); $action = "Record saved - $query"; # If no form entered, ask user to complete one } else { $action = "Please complete form"; } # Links to other pages in the application print <<"FOOTER"; <b>$action</b> <hr> Jump to - <a href=http://localhost/perlproj/cgi-bin/emp2.pl>View Emplo +yees Listing</a><br> Jump to - <a href=http://localhost/perlproj/cgi-bin/delemp.pl>Delete a +n Employee</a><br> Jump to - <a href=http://localhost/perlproj/cgi-bin/updatephoto.pl>Add + or update Employee Photo</a><br> <hr> Edited by Terry on July, 06 2014. </body></html> FOOTER
In reply to Re^2: How to get input text boxes populated
by terrykhatri
in thread How to get input text boxes populated
by terrykhatri
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |