I am trying to pass variables to a mysql statement. The variables were picked up via a CGI form. Somehow the variables just aren't working right. Observe the following:
my $sth=$dbh->prepare($query); # prepare the database for the SQL query
When doing the following, I get no response from the DB. However, if instead of:
$searchfor = em(param('searchTerm'));
I placed:
$test = name;
in the sql statement it worked fine. To summarize, if I set a variable within the code, it works, if I rely on the cgi variable it fails. Any hints as to what I might be doing wrong? Is there some sort of clean function to make the variable useable?
Any help will be greatly appreciated.
Code:
$searchFor = em(param('searchTerm'));
$searchField = em(param('field'));
my $query;
my $query="select * from address where $searchField like \"%$searchFor%\"";
my $sth=$dbh->prepare($query); # prepare the database for the SQL query
When doing the following, I get no response from the DB. However, if instead of:
$searchfor = em(param('searchTerm'));
I placed:
$test = name;
in the sql statement it worked fine. To summarize, if I set a variable within the code, it works, if I rely on the cgi variable it fails. Any hints as to what I might be doing wrong? Is there some sort of clean function to make the variable useable?
Any help will be greatly appreciated.