By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,747 Members | 1,683 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,747 IT Pros & Developers. It's quick & easy.

Variable in boolean query

P: n/a
I am a MySQL/PHP beginner and have gotten further than I expected. I am
developing a web based library catalog. After getting everything
configured, I have been working on various query formats. System is Mac
OS 10.3.8, PHP 5, MySQL 4.1.

I would like to use boolean queries as shown below, but I cqn't seem to
get the $_POST variable sytax correct. Any pointers would be enormously
helpful.

From the MySQL command line, this query works:

mysql> select * from record where match
(author,title,notes,other_entries) against ('+beethoven +symphonies' in
boolean mode);
However, when trying to take form input and build the same query in a
PHP script, something in the following doesn't work:
$name = $_POST['name'];
$title = $_POST['title'];
$result = mysql_query ("select * from record where match
(author,title,notes,other_entries) against ('+$name +$title' in boolean
mode)"), $connection);

For comparison purposes, the following works perfectly on my system:

$result = mysql_query ("select * from record where author regexp
'$name' and title regexp '$title'", $connection);
Thanks,
RHB
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Rhio Barnhart wrote:
$result = mysql_query ("select * from record where match
(author,title,notes,other_entries) against ('+$name +$title' in boolean
mode)"), $connection);


Untested, but try this:

$result = mysql_query ("select * from record where match
(author,title,notes,other_entries) against ('+{$name} +{$title}' in
boolean mode)"), $connection);

or this:
$result = mysql_query ("select * from record where match
(author,title,notes,other_entries) against ('+" . $name . ' +' . $title
.. "' in boolean mode)"), $connection);
I have the feeling that the '+' in '+$varname' is being interpreted as
an arithmetic operator. I could be totally wrong, though.

JP

--
Sorry, <de*****@cauce.org> is a spam trap.
Real e-mail address unavailable. 5000+ spams per month.
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.