List:General Discussion« Previous MessageNext Message »
From:Douglas Brantz Date:April 25 2000 10:26pm
Subject:Need Help with Checkboxes
View as plain text  
Here is what I have so far:  The web page displays everything ok but I
am still fuzzy on how to actually pass the array of all the checkbox ids
to the Links table:

Brief summary:  I have three tables in a database
labs (lab_id, lab_title)
software (software_id,software_title)
links (link_id, lab_id, software_id)

Script follows below:

Now, I am working on a form where the lab is selected from a drop down
menu and then all the software titles are displayed with checkboxes next
to them.  So I am not sure one - how I would display this page if
software has already been selected in the past - I guess I could have a
seperate update page and only labs that didn't have any software
selected would show in the drop down menu. or I could check against the
links table so I can display all the checked checkboxes as well as show
any new additions of labs and software.  My last problem is how to pass
an array such as the checkbox id info to a new form so that it can be
inserted into the links table- then again I might have to update instead
of insert.  I'm hanging on by the skin of my teeth.

Again, thanks for all the help !

Douglas


#!/usr/bin/perl -w
#

#use strict
use diagnostics;
use CGI;
use DBI;
#Setup main program
my $query = new CGI;

#Print out a contect type for http/1.0 compatibility
print $query->header("text/html");

#--------------Open Database---------------

my $dbh =
DBI->connect("DBI:mysql:database:localhost","username","password");
#--------------------------------------------------------------
#
#      Here goes the drop down menu

my $sth = $dbh->prepare("select lab_title,lab_id from lab")
or die $DBI::db_errstr;
$sth->execute;

my $numrows = $sth->rows;
if ($numrows == 0)
{
   #("No Labs Found");
}


#Now set up an array and a hash:
my @sproject_values = ();
my %sproject_labels;

#Loop through all the records found and fill the array and hash:
my $i;
for( $i = 0; $i < $numrows; $i++ )
{
        my @row = $sth->fetchrow_array;
        push( @sproject_values, $row[1]);
        $sproject_labels{$row[1]} = $row[0];
}
:
$sth->finish;

#Begin HTML output
print $query->start_html (-title =>'Link Software',-BGCOLOR=>'#000000',
-background=>'/something.gif',-vlink=>'#ffffff',-alink=>'#ffffff',-link=>'#ffffff');

#The \n's in the following code only affect the output of the
#info that comes back on the next screen.
#
print "<font color=\"#009999\">";
# print data to screen for user to see
print "<h2><center>Software Menu";
print "</h2></center></font></P>";
print "<center>";
#
my $method="";
my $action="";
$method="post";
$action="http://localhost/cgi-bin/acs/linkit.pl";
#----------------------------------------------------------------------
#print "<body color=\"#000000\">";
print "<table border=0><tr><td><center>";
print "<B><CENTER><font color=\"yellow\">Software Linking
Menu</b></center>";
print $query->startform($method,$action);
print "<font color=\"blue\">";
print "<table border=1><tr><td align=right>";
print "<font color=\"#009999\">Select Lab</td><td>";
#In the form, create the drop down list:
print $query->scrolling_list({ -name=>'LABNAME',
-size=>'1',-values=>\@sproject_values, -labels=>\%sproject_labels} );
print "</td></tr></table><BR><font color=\"#009999\">";
$sth = $dbh->prepare(qq{SELECT * FROM software});
$sth->execute();
while (($id, $title) = $sth->fetchrow_array()) {
        print qq{<INPUT TYPE="checkbox" NAME="$id">$title </INPUT>};
}
$sth->finish;
$dbh->disconnect;
print "<br>";
print "<BR>";
print $query->submit(-name=>'Link Software to Lab');
print $query->endform;
print "</center>";
print "</td></tr></table>";
print "<a href=\"http://filename\">Back to Main Menu</a>";
print "<BR><BR>";
#End HTML


Thread
Need Help with CheckboxesDouglas Brantz26 Apr