in reply to Re: perl/CGI/DBI + odd behaviour
in thread perl/CGI/DBI + odd behaviour
The next script connects to the database and searches it;#THE LOGIN PAGE *********************** #!/biol/programs/perl/bin/perl -w use strict; use DBI; use CGI qw(:standard); my $cgi = new CGI; use CGI::Carp qw(fatalsToBrowser); print "Content-type:text/html\n\n"; print <<EOF; <h2>database</h2><BR> <FORM METHOD="post" ACTION="http://myhost/~maisie/cgi-bin/database/ +frontpage.cgi"> <h3>Enter user name</h3> <INPUT TYPE="TEXT" NAME="username_box" SIZE="10"> <h3>Enter password</h3><INPUT TYPE="password" NAME="password_box" S +IZE +="10"> <INPUT TYPE="SUBMIT" value="Log in"> </FORM> </BODY></HTML> EOF
#!/biol/programs/perl/bin/perl -w use strict; use DBI; use CGI qw(:standard); my $cgi = new CGI; my $username = $cgi->param('username_box'); my $password = $cgi->param('password_box'); my ($sth, $sth2); my $dbh = DBI->connect("DBI:mysql:host=myhost;database=my_db", "$us +e +rname","$password", {PrintError =>0, RaiseError => 1}) || die "Dat +aba +se connection not made"; my $plate = $cgi->param("plate"); print $cgi->start_form (-method => "POST"); print $cgi->textfield (-name => "plate", -value => $plate,-size => +40); print $cgi->submit (-name => "button", -value=>"search"); print $cgi->end_form (); print "Search results for keyword: $plate \n", $cgi->escapeHTML; $sth2 = $dbh->prepare (qq{ SELECT * FROM plate WHERE plate_id LI +KE +? }); $sth2->execute("%" . $plate . "%" ); my $sql = qq{select * from plate}; $sth = $dbh->prepare ($sql); $sth->execute(); while (my $row = $sth->fetchrow_arrayref) { print join ("\t", @$row), "<P>"; } $dbh->disconnect(); print $cgi->end_html ();
|
|---|