in reply to Database Search

A few comments:

1. You don't need to chomp CGI input.

2. A database is designed to do complex queries. We use databases so we don't have to do extra work in Perl to sort out the things we need. Instead, we only ask for what we need, and let the database do the grunt work for us (it's more efficient anyway):

my $name = param('name'); # you may want to prevent search metacharacters: $name =~ s/(\%|_)/\\$1/g; my $sth = $dbh->prepare( "select * from clients where name like ?" ); $sth->execute($name) or die "Whoops!"; while ($sth->fetchrow_hashref) { ... }
Of course, always use placeholders!

3. Who said something has to be in a textbox to submit to a form? Use <input type=hidden>. Each submit button would look something like this:

<form method=post> <input type=hidden name=action value="more_info"> <input type=hidden name=name value="whatever"> <input type=submit value="More Info"> </form>
I don't understand your "alternative" of storing values in a "hash array." Again, you shouldn't have to store anything special/extra in a Perl datastructure, you just need to know the right thing to ask the database so it gives you what you want, and in the format you need.

blokhead

Replies are listed 'Best First'.
Re^2: Database Search
by jZed (Prior) on Jul 15, 2004 at 02:30 UTC
    A minor correction:
    my $sth = $dbh->prepare( "select * from clients where name like ?" ); $sth->execute($name) or die "Whoops!"

    That should be $sth->execute("%$name%") or somesuch use of wildcards in the execute.