--- Gordon Stewart <[EMAIL PROTECTED]> wrote:
> On 5/1/05, Gordon Stewart <[EMAIL PROTECTED]> wrote:
> > Problem with syntax :-
>
> > PHP Code:
> > $query = "SELECT * FROM BusNZ WHERE Unique='$matches[1]'";
> >
>
> it should be :-
>
> SELECT * FROM `BusNZ` WHERE `Unique`=$matches[2]
>
> Me thinks I should use the online MYSQL system more -It tells me the
> syntax to use (sometimes) :)
The command-line tools are definitely a help. PHPMyAdmin is not bad. You can
also get some assistance by displaying the query when an error occurs:
$r=mysql_query($q,$db) or die("<pre>$q<br>".mysql_error()."</pre>");
In your example you have a MySQL keyword which must be enclosed in back-tick
style of quotes.
For your PHP code you built the query in a double-quoted string. This is fine
but frequently complex variables like array elements do not get processed
properly. Something like this:
$query = "SELECT * FROM BusNZ WHERE Unique='$matches[1]'";
should be replaced with:
$query = "SELECT * FROM BusNZ WHERE `Unique`='${matches[1]}'";
The curly braces allow PHP to process the complex variable properly.
James
_____
James D. Keeline
http://www.Keeline.com http://www.Keeline.com/articles
http://Stratemeyer.org http://www.Keeline.com/TSCollection
http://www.ITeachPHP.com -- Free Computer Classes: Linux, PHP, etc.
Spring Semester Begins Jan 31 -- New Classes Start Every Few Weeks.
Community email addresses:
Post message: [email protected]
Subscribe: [EMAIL PROTECTED]
Unsubscribe: [EMAIL PROTECTED]
List owner: [EMAIL PROTECTED]
Shortcut URL to this page:
http://groups.yahoo.com/group/php-list
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/php-list/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/