richm05 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use CGI; use DBI; use CGI::Carp qw(fatalsToBrowser); #Create new CGI object my $cgi = new CGI; #Connect to DB my $dbh = DBI->connect("DBI:mysql:XXXXX:XXXXX","XXXXX","XXXXX") or die $DBI::errstr; #Print html header print $cgi->header("text/html"); #pull in keyword from form my $keyword = $cgi->param("keyword"); #prepare statement my $sth = $dbh->prepare("SELECT * FROM `productTable` WHERE `mfg` like '%$keyword%' OR `productID` like '%$keyword%' OR `desc` like '%$keyword%'") or die; #execute statement $sth->execute() or die; #print results while (my $rec = $sth->fetchrow_hashref) { print qq( <table> <tr> <td align="left">$rec->{mfg}</td> <td align="left">$rec->{productID}</td> <td align="left">$rec->{desc}</td> </tr> </table> ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: MySQL Keyword Search
by moritz (Cardinal) on Aug 15, 2007 at 20:20 UTC | |
|
Re: MySQL Keyword Search
by shmem (Chancellor) on Aug 15, 2007 at 20:23 UTC | |
by richm05 (Initiate) on Aug 16, 2007 at 00:32 UTC | |
|
Re: MySQL Keyword Search
by spatterson (Pilgrim) on Aug 17, 2007 at 11:11 UTC |