script not working correctly



Hello All

I am trying to get this script, to work although i'm sure something is
missing, not sure what though. I see that whatever you search for,
executes the query, so i'm not sure how to take the query from the html
form and pass it properly into my .cgi script. This is my searchdb.cgi
script. Thank you,,.

#!/usr/bin/perl
use CGI;
use DBI;

$db="mydb01";
$host="localhost";
$user="username";
$password="password";
$query = new CGI;

use CGI::Carp qw(fatalsToBrowser);

print "Content-type: text/html\n\n";

print "<html><head><title>MYSQL Search";
print "</title></head><body><h1>";
print "MYSQL Search</h1><p>";

my $dbh = DBI->connect ("DBI:mysql:database=$db:host=$host",
$user,
$password)
or die "Can't connect to database:
$DBI::errstr\n";

$sth = $dbh->prepare("select user_login from people")
or die("Couldn't prepare");

$sth->execute;

while (@row = $sth->fetchrow_array){
print "id: $row[0], name: $row[1]\n";
print "\n";
}

print "</body></html>\n";
$dbh->disconnect;

################################################

searchdb.html

<html>
<head>
<title>
Database Access
</title>
</head>
<body>
<h1>
Database Access
</h1>
<p>
<form action="cgi-bin/searchdb.cgi" method=post>
<br>
search:
<input type=text name=place>
<br>
<input type=submit value="Search database">
</form>
</body>
</html>

.



Relevant Pages

  • Re: any pointers please? combine words script
    ... use CGI qw/:standard/; ... # script is in development, ... # the html in another place ... sub get_html { ...
    (comp.lang.perl.misc)
  • Re: CGI advice
    ... and results in a table of links from the query results. ... should I go XML to HTML (via some ... If this is the start to a large application suite you would be silly not to, if it is a few one off CGI scripts then there is not likely any need, if it is somewhere in between I say hack it up and see how far you get, then refactor if the need presents itself. ... Whether you use its HTML generation abilities is more a matter of preference, personally I don't, but then I also use a home grown templating system which I already told you not to do :-). ...
    (perl.beginners)
  • Re: Need help
    ... My script works well with the sample data that I ... when the cgi script is run. ... If you are having a problem with your Perl script and want help, ... click in it and paste my html content or script in it. ...
    (comp.lang.perl.misc)
  • Re: CGI - HTTP 500 Internal server error
    ... What is a "HTML error"? ... most common problem is, as stated above, a missing script header. ... number and attach a STRSRVJOB and STRDBG to it to do debugging. ... To make CGI scripts a bit more verbose, have a look at the ScriptLog (or ...
    (comp.sys.ibm.as400.misc)
  • RE: CGI.PM and HTML Templates
    ... John Pretti wrote: ... the following script to use an html template? ... the cgi program. ... You can remove the html code from the ...
    (perl.beginners)