Re: variables
| From: | Matt McClanahan | Date: | Sat, 23 Sep 2000 02:13:03 +0000 |
| Subject: | Re: variables | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-17404@lists.php.net to get a copy of this message | ||
On Wed, 20 Sep 2000, Wayne Michel wrote:
> Hi,
>
> I am new to PHP and am muddling through. However, I have stumbled and would
> like assistance.
>
> I have the following lines of code:
>
> if ($action == "sort")
> {
> $query = "SELECT * FROM $tableName ORDER BY $orderField;" ;
> }
> if ($action == "pmg")
> {
> # $query = "SELECT * FROM $tableName WHERE model_category = $catField
>
> Entering the following URL works:
> catalogue.php?action=sort&orderField=Model
>
> Entering the following DOES NOT work:
> catalogue.php?action=pmg&catfield=Corgi
>
> Can some advise why?
Two things. First, assuming the code is verbatim, you didn't close the
quotes on your $query line for the 'pmg' case.
$query = "SELECT * FROM $tableName WHERE model_category = $catfield";
Second, assuming you're trying to find all rows where model_category is
set to the value in $catfield, you need to put $catfield itself in quotes.
Otherwise, SQL will think you're trying to say "Where the value in
model_category is equal to the value in the field named $catfield".
The query should look something like this:
$query = "SELECT * FROM $tableName WHERE model_category=\"$catfield\"";
Matt