print start_form( -action=>'results.cgi'); various form stuff.... print end_form; #### use DBI; use CGI::Cookie; use CGI qw /:standard/; use warnings; #checking if cookie is set, if not redirecting to login my %cookies = CGI::Cookie->fetch; if (! defined $cookies{'authorized'}) { print redirect('login.cgi') } #connecting to DB my $dbh = DBI->connect("dbi:SQLite:dbname=/path/to/database.db","",""); # getting artist info my $sth = $dbh->prepare('select artistid, name from artist'); $sth->execute; # getting genre info my $sth2 = $dbh->prepare('select genreid, name from genre'); $sth2->execute; #printing header print header, start_html('Database Search'), h2('Select items from the dropdown menus to help filter your results.'), br,br, end_html; print start_form(-action=>'results.cgi'); end_form; ### THIS CAUSES REDIRECT TO RESULTS WHEN USER HITS SUBMIT ############################POPUPS###################### #displaying artist dropdown my @artistValues; my %artistLabels; #this push adds to beginning of values, then it gets set to 'Make a selection' as the default for the dropdown push (@artistValues, -1); print h4('Please select an artist'); $artistLabels{-1} = "Make a selection"; while (my @row = $sth->fetchrow_array) { #2 columns in DB, first is ID second is NAME my $artistId = $row[0]; my $artistName = $row[1]; push(@artistValues,$artistId); $artistLabels{$artistId} = $artistName; } print popup_menu(-name=>'artist', -values=>\@artistValues, -labels=>\%artistLabels); $userArtist = param('artist'); #displaying genre dropdown my @genreValues; my %genreLabels; push (@genreValues, 'Make a selection'); print br,br; print h4('Please select a genre'); $genreLabels{-1} = "Make a selection"; while (my @row = $sth2->fetchrow_array) { my $genreId = $row[0]; my $genreName = $row[1]; push (@genreValues, $genreName); $genreLabels{$genreId} = $genreId; } print popup_menu(-name=>'genre', -values=>\@genreValues, -lables=>\%genreLabels); $userGenre = param('genre'); print br,br; ######################################################################## #displaying trackname textbox print "Track name: ",textfield('trackname'),br,br submit('SEARCH'), $trackName = param('trackname'); while(my @row = $sth->fetchrow_array){ foreach $item (@row){ print "$item "; }print br; } print br,br,br,br,a({href=>'http://www.blablabla.com/logout.cgi'},'Logout');