Re: expanding inside quotes problem
| From: | David Robley | Date: | Tue, 07 Nov 2000 01:15:49 +0000 |
| Subject: | Re: expanding inside quotes problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-24031@lists.php.net to get a copy of this message | ||
On Tue, 07 Nov 2000, Andrew Threlfall wrote:
> I've a problem with the folowing line
>
> $results = mysql_query("SELECT * FROM group WHERE postcode REGEXP
> '^$query[:digit:]+.*'", $db)
>
> when run I get:
> "Parse error: parse error, expecting
T_STRING' or
> T_VARIABLE' or
> `T_NUM_STRING' "
>
> I think the problem is that php is treating the square brackets as a regular
> expression, and attempting to expand it(?). I can stop this by using single
> quotes, but then the variable in the string will not be expanded.
>
> I'm not sure what to escape in order that the query get passed correctly.
>
> I hope I've made it relatively clear.
> Thanks
Try isolating the variable from the string, thus:
$query =
"SELECT * FROM group WHERE postcode REGEXP > '^" . $query .
"[:digit:]+.*'";
$results = mysql_query($query,$db);
Then if needed you may be able to echo the query string to try and pinpoint
the problem further
--
David Robley | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
AusEinet | http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA