Been tampering to modify a .pl script that fetches email addresses from a database. I can get it to send the emails fine if i query it like this in the script:
my $sth = $dbh->prepare("SELECT email FROM persons");
But i need this to work as i have different languages to serve:
my $sth = $dbh->prepare("SELECT email FROM persons WHERE page = $page");
The $page is defined in the form that uses the script. And defined like this with all the other variables in the script:
my $page = $q->param('page');
Since i have only two languages to serve, would it be better to make an if - else for the value of $page and thus not setting it as a variable?
Hope this is clear - i didnt know how much of the scipt was relevant to show.
Kind Regards
/Hafnius
Sorry bout that - just found the solution. I had forgotten two ''.
So the qeury should be like this to work:
my $sth = $dbh->prepare("SELECT email FROM persons WHERE page='$page'")
Instead of:
my $sth = $dbh->prepare("SELECT email FROM persons WHERE page = $page")
What a wonderfull feeling when this stuff worx.
Kind Regards
/Hafnius - master of PERL :)
Are you using dbi->quote()?
my $page = "whatever I have in here: maybe some!@#";
$page = dbh->quote($page);
my $sth = $dbh->prepare("SELECT email FROM persons WHERE page = $page")
You can also add a datatype argument but you will have to consult the DBI docs for that.