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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
help in getting the value right



Jul 5, 2000, 12:42 PM

Post #1 of 1 (461 views)
help in getting the value right Can't Post

Please help me with this program

I am trying to update the form values to the database. I have a form (mod.cgi) with 2 checkboxes and
one text box.(mod.cgi retrieves data from the database. If the value is 1 in the database,the checkbox shows up checked and if the value is 0, the checkbox shows up unchecked). I want to edit the values in the form by checking it or unchecking it. It is updating all the form values except on one condition. When i check the checkbox, it is not updating to the database and when i uncheck the checkbox, it is updating. The textbox value is also getting updated. I need to fix this problem.
Please help me if the following program has a mistake.

objective: If the user submits the button to a form (mod.cgi), the form should
retrieve data from the database and display a modify button. when the user edits the values in the form (mod.cgi) and clicks the modify button, it should update the record.
It is updating for all the values except the checked values.
Please help me

sub printform {
@fields = ("conferenceRoomName","overHead","tv_Vcr")#database columns
$value =$query->param('conferenceRoomId');
if ($value) #if the user selects an option
&getinf; #retrieves data from the database
&printform1; # prints the form with the retrieved information from the database and displays the modify button
} # end of printform
#subroutines:getinf and printform1;
sub getinf {
$value =$query->param('conferenceRoomId');
my $selStr ='';
my $colList = '';
my $recset = '';
my @vals = ();
for ($i=0; $i < scalar(@fields); $i++)
if ($fields[$i] =~ /date/) {
$colList .= "to_char($fields[$i], \'MMDDYYYY\') as $fields[$i]";
} #end if
else {
$colList .= "$fields[$i]"}
if ($i < scalar(@fields)-1)
{$colList .= ","}
$selStr ="Select $colList from ConferenceRooms where conferenceRoomId=$value";
$recset = $syb->prepare($selStr);
@vals =$recset->fetchrow;
for ($i =0; $i < scalar(@fields); $i++) {
$fieldvals{$fields[$i]} = $vals[$i];
return %fieldvals;
} # end of getinf
sub printform1 {
print <<"html";
<form method ="post" action ="modify1.cgi">
<tr><td><B><font size=6>Conference Room: </font></B></td>
<input type ="text" name="conferenceRoomName" value ="$fieldvals{'conferenceRoomName'}"></tr>
<table><tr><td><B><font size =6>OverHead: </font></B></td>
if ($fieldvals{'overHead'} == 1) #if the database value is for overHead is 1
print <<"html";
<td><input type = "checkbox" name="overHead" value="$fieldvals{'overHead'}" checked> </td>
elsif ($fieldvals{'overHead'} ==0){
print <<"html";
<td><input type ="checkbox" name="overHead" value="$fieldvals{'overHead'}"></td>
else {
print <<"html";
<td><input type ="checkbox" name ="overHead" value="$query->param('overHead')";
print <<"html";
<table><tr><td><B><font size =6>TV/VCR: </font></B></td>
if ($fieldvals{'tv_Vcr'} == 1) {
print <<"html";
<td><input type = "checkbox" name="tv_Vcr" value="$fieldvals{'tv_Vcr'}" checked> </td>
else {
print <<"html";
<td><input type ="checkbox" name="tv_Vcr" value="0"></td>
print <<"html";
<form name="mod" method ="post" action="mod.cgi">
<BR> <font size =5><B><input type ="submit" name= "modify" value= "Modify"></B></font>
} # end of printform1
$getit = $query->param('modify');
if ($getit eq 'Modify') {
sub doUpdate {
@fields = ("overHead","slideProj","tv_Vcr","videoConference","seats","active");
my $updStr= " ";
my $val =" ";
#my $colStr = " ";
$value1 = $query->param('hiddenvalue');
for ($i=0;$i<scalar(@fields);$i++) {
if ($query->param($fields[$i])) {
$val = $query->param($fields[$i]);
else {$val = 0;}
$colStr .="$fields[$i]\=$val";
$colStr .= "," if ($i < (scalar(@fields)-1));
#print "values from the form $colStr\n";
$updStr ="update ConferenceRooms set $colStr where conferenceRoomId =$value1";
#print " Updated values. $colStr";
$sybHandle->execute() &#0124; &#0124; &writeError('Conference Room cannot be updated');
$rc = $sybHandle->finish();
$message = "<b>Conference Room has been updated</b><p>";
print <<"html";
<B><center><font size=5> Record has been Updated </font></center></B>
} # end of doUpdate


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives