Query Syntax - WHERE fieldname1="fieldvalue1" AND fieldname2="fieldvalue2"

Query Syntax - WHERE fieldname1="fieldvalue1" AND fieldname2="fieldvalue2"

am 22.05.2007 17:07:15 von Mark Abrams

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

RE: Query Syntax - WHERE fieldname1="fieldvalue1"

am 22.05.2007 17:31:00 von luis.moreira

I think you have an "operator\precedence" issue.

Try=20

$query =3D "SELECT $field_name FROM classifieds=20
WHERE=20
($field_name1 =3D '$field_value1')=20
AND=20
($field_name2 =3D'$field_value2')
";

This will stop you from eventually ANDing the wrong pair...


-----Original Message-----
From: Mark Abrams [mailto:mark@hospitalsystemsgroup.com]=20
Sent: ter=E7a-feira, 22 de Maio de 2007 16:07
To: php-windows@lists.php.net
Subject: [PHP-WIN] Query Syntax - WHERE fieldname1=3D'fieldvalue1'
ANDfieldname2=3D'fieldvalue2'

Query Syntax -



I have a syntax error when I am using an AND in the WHERE clause for a=20
double field=3Dvalue restriction



#1 RUNS OK

$query =3D "SELECT $field_name FROM classifieds WHERE $field_name =
'$field_value'";



$result =3D mysql_query($query) or die(mysql_error());



#2 FAILS

$query =3D "SELECT $field_name FROM classifieds WHERE $field_name1 =
'$field_value1' AND $field_name2 =3D'$field_value2'";



$result =3D 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=20
for the right syntax to use near 'FROM classifieds WHERE trans_type =3D =
'For=20
Sale' AND category =3D'Boats'' at line 1 in C:\apache2triad\htdocs\



Background: I call a function and pass a $field_name =3D $field_value =
pair.=20
This works OK. When I add a second field_name =3D $field_value pair the =
query

dies.



Data excerpt from TABLE classifieds:

trans_type =3D Free
category =3D Books





Also, Can anyone recommend a good book on mySQL / php? I could not find =
a=20
good example of my problem in the online manual =
http://www.mysql.com/doc.



TIA

Mark

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

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

RE: Query Syntax - WHERE fieldname1="fieldvalue1" AND fieldname2="fieldvalue2"

am 22.05.2007 17:54:55 von Arno Kuhl

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

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

Re: Query Syntax - WHERE fieldname1="fieldvalue1"ANDfieldname2="fieldvalue2"

am 22.05.2007 18:05:39 von Mark Abrams

This did not work. But 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_type ='For Sale')' at line 1 in
C:\apache2triad\htdocs\sunlakes\test3.php on line 82




""Luis Moreira (ESI-GSQP)"" wrote in message
news:014e01c79c86$3f34e3d0$bd9eab70$%moreira@esi.pt...
I think you have an "operator\precedence" issue.

Try

$query = "SELECT $field_name FROM classifieds
WHERE
($field_name1 = '$field_value1')
AND
($field_name2 ='$field_value2')
";

This will stop you from eventually ANDing the wrong pair...


-----Original Message-----
From: Mark Abrams [mailto:mark@hospitalsystemsgroup.com]
Sent: terça-feira, 22 de Maio de 2007 16:07
To: php-windows@lists.php.net
Subject: [PHP-WIN] Query Syntax - WHERE fieldname1='fieldvalue1'
ANDfieldname2='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

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

This did not work. Re: [PHP-WIN] Query Syntax - WHERE fieldname1="fieldvalue1" AND fieldname2="fiel

am 22.05.2007 18:09:06 von Mark Abrams

This did not work. Thank you for trying.



Both parms are string



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



Mark

""Arno Kuhl"" 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

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

Failed Re: [PHP-WIN] Query Syntax - WHERE fieldname1="fieldvalue1" AND fieldname2="fieldvalue2"

am 22.05.2007 18:18:58 von Mark Abrams

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"" 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

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

Re: Query Syntax - WHERE fieldname1="fieldvalue1" AND fieldname2="fieldvalue2"

am 22.05.2007 18:35:06 von Stut

Mark Abrams wrote:
> #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\

Have you tried printing out $query to see exactly what you're sending?
Seems like a logical first step to me. Something about it is clearly
wrong, and I'm guess it's an empty or wrong $field_name value.

-Stut

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

Re: Query Syntax - WHERE fieldname1="fieldvalue1" AND fieldname2="fieldvalue2"

am 22.05.2007 18:42:18 von James Crow

Often the error in the SQL statement is just before the part echoed in the
error message. Check your $field_name to see if it has any special characters
or a semicolon in it. Maybe something like:





or this:

echo "\$query = $query\n";


Thanks,
James



On Tuesday 22 May 2007 11:07, Mark Abrams wrote:
> 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

query strings & printouts Re: [PHP-WIN] Query Syntax - WHERE fieldname1="fieldvalue1" AND fiel

am 22.05.2007 19:47:58 von Mark Abrams

Here are the query strings & printouts:

This works OK
$query = "SELECT $field_name FROM classifieds WHERE $field_name1 =
'$field_value1' AND $field_name2 = '$field_value2'";

SELECT FROM classifieds WHERE trans_type ="For Sale"

FAILS

#1
$query = "SELECT $field_name FROM classifieds WHERE $field_name1 =
'$field_value1' AND $field_name2 = '$field_value2'";

SELECT FROM classifieds WHERE trans_type = 'For Sale' AND category =
'Books'

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_type = 'For Sale'' at line 1 in
C:\apache2triad\htdocs\sunlakes\test3.php on line 82

#2
$query = "SELECT $field_name
FROM classifieds
WHERE ($field_name1 = '".$field_value1."')
AND ($field_name2 = '".$field_value2."')";

SELECT FROM classifieds WHERE (trans_type = 'For Sale') AND (category =
'Books')


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






"Stut" wrote in message
news:46531BBA.5010207@gmail.com...
> Mark Abrams wrote:
>> #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\
>
> Have you tried printing out $query to see exactly what you're sending?
> Seems like a logical first step to me. Something about it is clearly
> wrong, and I'm guess it's an empty or wrong $field_name value.
>
> -Stut

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

RE: query strings & printouts Re: [PHP-WIN] Query Syntax - WHERE fieldname1="fieldvalue1" AND

am 22.05.2007 19:59:08 von Bill Bolte

"SELECT FROM classifieds WHERE trans_type =3D"For Sale""

SELECT what? $field_name looks to null or blank...



-----Original Message-----
From: Mark Abrams [mailto:mark@hospitalsystemsgroup.com]=20
Sent: Tuesday, May 22, 2007 12:48 PM
To: php-windows@lists.php.net
Subject: [PHP-WIN] query strings & printouts Re: [PHP-WIN] Query Syntax
- WHERE fieldname1=3D'fieldvalue1' AND fieldname2=3D'fieldvalue2'

Here are the query strings & printouts:

This works OK
$query =3D "SELECT $field_name FROM classifieds WHERE $field_name1 =
=
'$field_value1' AND $field_name2 =3D '$field_value2'";

SELECT FROM classifieds WHERE trans_type =3D"For Sale"

FAILS

#1
$query =3D "SELECT $field_name FROM classifieds WHERE $field_name1 =
=
'$field_value1' AND $field_name2 =3D '$field_value2'";

SELECT FROM classifieds WHERE trans_type =3D 'For Sale' AND category =
=3D

'Books'

Warning: mysql_query() [http://www.mysql.com/doc]: You have an error in
your=20
SQL syntax; check the manual that corresponds to your MySQL server
version=20
for the right syntax to use near 'FROM classifieds WHERE trans_type =3D
'For=20
Sale' AND trans_type =3D 'For Sale'' at line 1 in=20
C:\apache2triad\htdocs\sunlakes\test3.php on line 82

#2
$query =3D "SELECT $field_name
FROM classifieds
WHERE ($field_name1 =3D '".$field_value1."')
AND ($field_name2 =3D '".$field_value2."')";

SELECT FROM classifieds WHERE (trans_type =3D 'For Sale') AND
(category =
'Books')


Warning: mysql_query() [http://www.mysql.com/doc]: You have an error in
your=20
SQL syntax; check the manual that corresponds to your MySQL server
version=20
for the right syntax to use near 'FROM classifieds WHERE (trans_type =3D
'For=20
Sale') AND (tr' at line 2 in C:\apache2triad\htdocs\sunlakes\test3.php
on=20
line 85






"Stut" wrote in message=20
news:46531BBA.5010207@gmail.com...
> Mark Abrams wrote:
>> #2 FAILS
>>
>> $query =3D "SELECT $field_name FROM classifieds WHERE $field_name1 =
=
>> '$field_value1' AND $field_name2 =3D'$field_value2'";
>>
>> $result =3D 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=20
>> your SQL syntax; check the manual that corresponds to your MySQL
server=20
>> version for the right syntax to use near 'FROM classifieds WHERE=20
>> trans_type =3D 'For Sale' AND category =3D'Boats'' at line 1 in=20
>> C:\apache2triad\htdocs\
>
> Have you tried printing out $query to see exactly what you're sending?

> Seems like a logical first step to me. Something about it is clearly=20
> wrong, and I'm guess it's an empty or wrong $field_name value.
>
> -Stut=20

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

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

Re: query strings & printouts Re: [PHP-WIN] Query Syntax- WHERE fieldname1="fieldvalue1" AND f

am 22.05.2007 20:00:15 von Stut

Mark Abrams wrote:
> Here are the query strings & printouts:
>
> This works OK
> $query = "SELECT $field_name FROM classifieds WHERE $field_name1 =
> '$field_value1' AND $field_name2 = '$field_value2'";
>
> SELECT FROM classifieds WHERE trans_type ="For Sale"
>
> FAILS

Of course it does. You want to select *WHAT* from classifieds? As I
suspected. $field_name is empty or not defined.

> #1
> $query = "SELECT $field_name FROM classifieds WHERE $field_name1 =
> '$field_value1' AND $field_name2 = '$field_value2'";
>
> SELECT FROM classifieds WHERE trans_type = 'For Sale' AND category =
> 'Books'
>
> 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_type = 'For Sale'' at line 1 in
> C:\apache2triad\htdocs\sunlakes\test3.php on line 82

Ditto.

> #2
> $query = "SELECT $field_name
> FROM classifieds
> WHERE ($field_name1 = '".$field_value1."')
> AND ($field_name2 = '".$field_value2."')";
>
> SELECT FROM classifieds WHERE (trans_type = 'For Sale') AND (category =
> 'Books')
>
>
> 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

Ditto.

-Stut

> "Stut" wrote in message
> news:46531BBA.5010207@gmail.com...
>> Mark Abrams wrote:
>>> #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\
>> Have you tried printing out $query to see exactly what you're sending?
>> Seems like a logical first step to me. Something about it is clearly
>> wrong, and I'm guess it's an empty or wrong $field_name value.
>>
>> -Stut
>

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

RESOLVED - Thank you Stut - Re: [PHP-WIN] WHERE fieldname1="fieldvalue1" AND fieldname2="fieldval

am 22.05.2007 20:21:05 von Mark Abrams

Thank you Stut. I feel like a fool. Little gremlins removed the SELECT
column.

Everyone - I appreciate your support. Its easy to get a blind spot and I
have had one all morning.
Regards,
Mark


"Stut" wrote in message
news:46532FAF.7000803@gmail.com...
> Mark Abrams wrote:
>> Here are the query strings & printouts:
>>
>> This works OK
>> $query = "SELECT $field_name FROM classifieds WHERE $field_name1 =
>> '$field_value1' AND $field_name2 = '$field_value2'";
>>
>> SELECT FROM classifieds WHERE trans_type ="For Sale"
>>
>> FAILS
>
> Of course it does. You want to select *WHAT* from classifieds? As I
> suspected. $field_name is empty or not defined.
>
>> #1
>> $query = "SELECT $field_name FROM classifieds WHERE $field_name1 =
>> '$field_value1' AND $field_name2 = '$field_value2'";
>>
>> SELECT FROM classifieds WHERE trans_type = 'For Sale' AND category =
>> 'Books'
>>
>> 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_type = 'For Sale'' at line 1 in
>> C:\apache2triad\htdocs\sunlakes\test3.php on line 82
>
> Ditto.
>
>> #2
>> $query = "SELECT $field_name
>> FROM classifieds
>> WHERE ($field_name1 = '".$field_value1."')
>> AND ($field_name2 = '".$field_value2."')";
>>
>> SELECT FROM classifieds WHERE (trans_type = 'For Sale') AND
>> (category = 'Books')
>>
>>
>> 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
>
> Ditto.
>
> -Stut
>
>> "Stut" wrote in message
>> news:46531BBA.5010207@gmail.com...
>>> Mark Abrams wrote:
>>>> #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\
>>> Have you tried printing out $query to see exactly what you're sending?
>>> Seems like a logical first step to me. Something about it is clearly
>>> wrong, and I'm guess it's an empty or wrong $field_name value.
>>>
>>> -Stut
>>

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