RE: [PHP-DB] variable within regular expression

2003-04-04 Thread Rob Bryant
 -Original Message-
 From: Robbie Staufer [mailto:[EMAIL PROTECTED]
 Sent: Friday, April 04, 2003 3:59 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP-DB] variable within regular expression



 I have a php query form in which the user input must be converted to a
 regular expression before querying the db.  Something like this
 pseudo code:
  $var = $_GET['usr-input'];
  $var = '%$var%';
 SELECT * FROM table WHERE field LIKE $var.

 I can't find the right syntax to make this work.  Does anyone know?


I think maybe the single quotes don't interpolate the value of the variable.

In other words, let's say $var is 'fubar':

$var = '%$var%'; // - is literally %$var%

vs.

$var = %$var%; // - is %fubar%

Anyway, here's some of my code that is similar to (what I think) you're
trying to do:

if (isset($_GET['nstring'])) {
$nstring = addslashes($_GET['nstring']);
$squery = SELECT * FROM lead
   WHERE name LIKE '%{$nstring}%'
   ORDER BY source, ref_by, date DESC;
$sresult = mysql_query($squery);
} // etc...



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Query Help...

2003-03-10 Thread Rob Bryant
- Original Message -
From: NIPP, SCOTT V (SBCSI) [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, March 10, 2003 9:23 AM
Subject: [PHP-DB] Query Help...


 I am having a lot of trouble with a query that works fine from a
 basic SQL command line, but fails in my web script.  Here is the
portion of
 code including the query:

 mysql_select_db($database, $Prod);
 $query_groups = SELECT name FROM group;
 $groups = mysql_query($query_groups, $Prod) or die(mysql_error());

 Here is the error I am receiving:

 You have an error in your SQL syntax near 'group' at line 1


Have you tried using backticks in your query? E.g.,

$query_groups = SELECT name FROM `group`;

--
rob


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php