Searching database with perl script

S

servicio.hispano

I'm new at this and can't get this to work. I have this form where I'm
trying to search by last name but the page where the results should be
come up blank. I know I must be missing something simple. I apologize
if this is the wrong place to post this. Here's my code:

sub name_search(){
print $q->header();
print $q->start_html();
# if($submit) {


my $dbh = DBI->connect("DBI:mysql:policy",
"*******", "*******");
if($submit) {

my $sql = "SELECT polID, lname1, fname FROM
customers where lname1 = $lname1"; #trying to match the value in the
textfield
my $sth = $dbh->prepare($sql);
while(my($p, $l, $f) = $sth->fetchrow_array()){
print "<table>\n";
print
"<tr><td>$p</td><td>$l</td><td>$f</td></tr>\n";
print "</table>\n";
}

}else{
print $q->start_form();
print $q->hidden('op', 'name_search');
print $q->hidden('lname1', $lname1);
print "<table>";
print "<tr><td>Last Name</td><td>" .
$q->textfield('lname1', '$lname1', '', '') . $q->submit('submit',
'Search');
print "</td></tr>";
print "</table>";
print $q->end_form();
print $q->end_html();


#$sth->finish();
}
$dbh->disconnect();

}

The textbox and submit button shows up fine. I don't get any errors. I
just don't get anything in the results. It just goes to a blank page. I
know I've gotten this to work before but because of my job I haven't
had the chance to practice. What I learned I have forgotten.

Thanks for any help.
 
B

Brian Wakem

I'm new at this and can't get this to work. I have this form where I'm
trying to search by last name but the page where the results should be
come up blank. I know I must be missing something simple. I apologize
if this is the wrong place to post this. Here's my code:

sub name_search(){
print $q->header();
print $q->start_html();
# if($submit) {


my $dbh = DBI->connect("DBI:mysql:policy",
"*******", "*******");
if($submit) {

my $sql = "SELECT polID, lname1, fname FROM
customers where lname1 = $lname1"; #trying to match the value in the
textfield
my $sth = $dbh->prepare($sql);
while(my($p, $l, $f) = $sth->fetchrow_array()){


You can't fetch without execute.

$sth->execute();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,144
Latest member
KetoBaseReviews
Top