recently been working on a form to search an sql db, at the moment its a simple 3 fields but ive been unable to get the if statement working.
all the code is below.
Expand|Select|Wrap|Line Numbers
- #!/usr/bin/perl -w
- use CGI::Carp "fatalsToBrowser";
- use CGI ':standard';
- use DBI;
- $author=param('author');
- $keyword=param('keyword');
- $publisher=param('publisher');
- $user='user';
- $pass='pass';
- $info='DBI:mysql:database=user;host=mudfoot';
- $dbh=DBI->connect($info ,$user ,$pass) or
- die "Can't_connect_to_database";
- print header();
- $query1="SELECT * FROM book where Title='$keyword' AND Author='$author' AND Publisher='$publisher'";
- $query2="SELECT * FROM book WHERE Title='$keyword' AND Author='$author'";
- IF ($publisher = 'ANY') {
- $sth=$dbh->prepare($query2);
- }
- else
- {
- $sth=$dbh->prepare($query1);
- }
- $sth->execute;
- while(@result=$sth->fetchrow_array)
- {
- print "Book Title: $result[0], Publisher: $result[1], Author: $result[2], Quantity in Stock: $result[3], Cost: £$result[4] <BR>";
- }
- $sth->finish;
- $dbh->disconnect;
Thanks