Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^5: html checkbox and perl cgi

by tangent (Parson)
on Jan 18, 2014 at 21:27 UTC ( [id://1071146]=note: print w/replies, xml ) Need Help??


in reply to Re^4: html checkbox and perl cgi
in thread html checkbox and perl cgi

It's no bother. Most form inputs do need a value attribute, not just checkboxes. Select menus do have a value but it is contained within the <option> tags. Can you explain what you mean by "still doesn't work". If you comment out your db connection and exit(0); right after your print statements you will get the result in your browser.

Replies are listed 'Best First'.
Re^6: html checkbox and perl cgi
by AdrianJ217 (Novice) on Jan 18, 2014 at 22:48 UTC
    Thank you. So I did comment it out and put the print statements in as below but i got an internal server error which I guess means that there is something wrong with the html file?? Below is the CGI script. Thank you so much.
    #!/usr/bin/perl -w use strict; use DBI; use CGI; my $query = new CGI; print $query->header(); #my $my_database = "TrypSnoDB"; #my $localhost = "localhost"; #my $dsn = "DBI:mysql:$my_database:$localhost"; #my $db_user_name = "adrian"; #my $db_password = "temp_pass"; #my $dbh = DBI->connect("DBI:mysql:database=TrypSnoDB;host=localhost;m +ysql_socket=/private/software/mysql/mysql.sock","adrian","temp_pass", + {'RaiseError' => 1}); if ($query->param('submit1')){ my $family = $query->param('family'); my $TB = $query->param('TB'); my $LM = $query->param('LM'); my $HS = $query->param('HS'); my $SC = $query->param('SC'); my $AT = $query->param('AT'); my $db_query; print qq(TB: $TB<br>; print qq(LM: $LM)<br>; print qq(HS: $HS)<br>; print qq(SC: $SC)<br>; print qq(AT: $AT)<br>; } exit(0); if ($family eq "ALL") { $family = "'C/D' or ST.family='H/ACA'" } else { $family = "'$family'"; } $db_query = "SELECT ST.sno_name,HT.homolog_name FROM sno_Table ST, +Homolog_Table HT,sno_Homologs SH,Organism O WHERE ST.sno_id=SH.sno_id AND SH.homolog_id=HT.homolog_id AND HT.org_i +d=O.org_id and (ST.family=$family) and O.organism='$TB'"; my $sth = $dbh->prepare($db_query); $sth->execute(); my$total = $sth->rows; print "<table border=1>\n <tr> <th>snoRNA</th>\n <th>Homolog</th>\n </tr>\n"; while (my@row = $sth->fetchrow_array()){ my$sno_name = $row[0]; my$homolog_name = $row[1]; print "<tr>\n<td>$sno_name</d><td>$homolog_name</td></tr>\n"; } print "<tr> <th>TOTAL</th>\n <th>$total</th>\n </tr>\n"; print "</table>"; }
      OK, sorry I should have been clearer. You didn't copy the print statements correctly and you added a "}" right after them which caused errors. Another useful thing to do when you are debugging CGI scripts is to add the following line to the top of your script:
      use CGI::Carp('fatalsToBrowser');
      This will give you the reasons for the errors and where they occurred rather than the dreaded "Internal Server Error" message.

      Just to get you past this, maybe it would be easier to just put the below lines before your whole script - click the 'download' link at the bottom and then copy and paste it right on the top line, forcing your original down. The '__END__' will exclude everything that comes after, as if you had commented it all out.

      #!/usr/bin/perl -w use strict; use DBI; use CGI; use CGI::Carp('fatalsToBrowser'); my $query = new CGI; print $query->header(); if ($query->param('submit1')){ my $family = $query->param('family'); my $TB = $query->param('TB'); my $LM = $query->param('LM'); my $HS = $query->param('HS'); my $SC = $query->param('SC'); my $AT = $query->param('AT'); print "TB: $TB<br>"; print "LM: $LM<br>"; print "HS: $HS<br>"; print "SC: $SC<br>"; print "AT: $AT<br>"; } __END__
        Got it, thank you so much. So I tried it and the print statements were displayed correctly once I clicked submit, so that part is ok. I guess the problem is with the query to mySQL?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1071146]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found