Failed Re: [PHP-WIN] Query Syntax - WHERE fieldname1='fieldvalue1' AND fieldname2='fieldvalue2'
| From: | Mark Abrams | Date: | Tue, 22 May 2007 16:18:58 +0000 |
| Subject: | Failed Re: [PHP-WIN] Query Syntax - WHERE fieldname1='fieldvalue1' AND fieldname2='fieldvalue2' | ||
| References: | 1 2 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-27937@lists.php.net to get a copy of this message | ||
Thank you for trying.
Warning: mysql_query() [http://www.mysql.com/doc]: You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near 'FROM classifieds WHERE trans_type = 'For
Sale' AND trans' at line 2 in C:\apache2triad\htdocs\sunlakes\test3.php on
line 85
Also with ( )
Warning: mysql_query() [http://www.mysql.com/doc]: You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near 'FROM classifieds WHERE (trans_type = 'For
Sale') AND (tr' at line 2 in C:\apache2triad\htdocs\sunlakes\test3.php on
line 85
""Arno Kuhl"" <akuhl@telkomsa.net> wrote in message
news:MOEGIFNOKGHCLJCEILGBIEDOIJAA.akuhl@telkomsa.net...
> Try this:
>
> $query = "SELECT $field_name
> FROM classifieds
> WHERE $field_name1 = '".$field_value1."'
> AND $field_name2 = '".$field_value2."'";
>
> Also, check the data types - if $field_name1/2 is an int then you don't
> need
> the single quotes.
>
> Arno
>
>
>
> -----Original Message-----
> From: Mark Abrams [mailto:mark@hospitalsystemsgroup.com]
> Sent: 22 May 2007 05:07
> To: php-windows@lists.php.net
> Subject: [PHP-WIN] Query Syntax - WHERE fieldname1='fieldvalue1' AND
> fieldname2='fieldvalue2'
>
>
> Query Syntax -
>
>
>
> I have a syntax error when I am using an AND in the WHERE clause for a
> double field=value restriction
>
>
>
> #1 RUNS OK
>
> $query = "SELECT $field_name FROM classifieds WHERE $field_name =
> '$field_value'";
>
>
>
> $result = mysql_query($query) or die(mysql_error());
>
>
>
> #2 FAILS
>
> $query = "SELECT $field_name FROM classifieds WHERE $field_name1 =
> '$field_value1' AND $field_name2 ='$field_value2'";
>
>
>
> $result = mysql_query($query) or die(mysql_error());
>
>
>
> dies with the following message:
>
>
>
> Warning: mysql_query() [http://www.mysql.com/doc]: You have an error in
> your
> SQL syntax; check the manual that corresponds to your MySQL server version
> for the right syntax to use near 'FROM classifieds WHERE trans_type = 'For
> Sale' AND category ='Boats'' at line 1 in C:\apache2triad\htdocs\
>
>
>
> Background: I call a function and pass a $field_name = $field_value pair.
> This works OK. When I add a second field_name = $field_value pair the
> query
> dies.
>
>
>
> Data excerpt from TABLE classifieds:
>
> trans_type = Free
> category = Books
>
>
>
>
>
> Also, Can anyone recommend a good book on mySQL / php? I could not find a
> good example of my problem in the online manual http://www.mysql.com/doc.
>
>
>
>
> TIA
>
> Mark
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php