I am creating a search function in my site, in which I used Perl and MySQL.
I am just wondering, about this....
In the search box, I am putting a popup_menu, using CGI.pm to create it, with a few variables, such as 10, 20, 40, 80, and 120 "results to show".
So in my search results I am putting this code:
$sth = $dbh->prepare("SELECT * FROM products WHERE ? IN (prod_name
+,prod_desc) LIMIT 0,?");
$sth->execute($search_term,$max_recs1);
I am very concerned about the second limit number, since $max_recs1 is this:
$max_recs1 = param("max_rec");
So if I put it in the query itself, and someone posted to the search form, a max_rec value of 100 DELETE FROM products
or something like that I don't know that it would work, but if it did, that COULD be disasterous.
So, is the code I put above ok?
Because I'm getting this error:
DBD::mysql::st execute failed: You have an error in your SQL syntax ne
+ar ''10'' at line 1 at /home/user/path/to/pages/products.dat line 182
+6.
10 is the number I selected when I tested the search.
Thank you for any tips/advice you have.
thx,
Richard
Title edit by tye
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.