php-windows Digest 23 May 2007 04:25:20 -0000 Issue 3235

Topics (messages 27930 through 27947):

Query Syntax - WHERE fieldname1='fieldvalue1' AND fieldname2='fieldvalue2'
        27930 by: Mark Abrams
        27933 by: Luis Moreira (ESI-GSQP)
        27934 by: Arno Kuhl
        27935 by: Mark Abrams
        27936 by: Stut
        27939 by: James Crow
        27941 by: tg-php.gryffyndevelopment.com
        27944 by: tg-php.gryffyndevelopment.com

Re: PHP generated Excel Spreadsheets
        27931 by: tg-php.gryffyndevelopment.com
        27932 by: Luís Ferro

Failed  Re: [PHP-WIN] Query Syntax - WHERE fieldname1='fieldvalue1' AND 
fieldname2='fieldvalue2'
        27937 by: Mark Abrams

This did not work.  Re: [PHP-WIN] Query Syntax - WHERE fieldname1='fieldvalue1' 
AND fieldname2='fieldvalue2'
        27938 by: Mark Abrams

query strings &  printouts  Re: [PHP-WIN] Query Syntax - WHERE 
fieldname1='fieldvalue1' AND fieldname2='fieldvalue2'
        27940 by: Mark Abrams
        27942 by: Bill Bolte
        27943 by: Stut

RESOLVED - Thank you Stut   - Re: [PHP-WIN]  WHERE fieldname1='fieldvalue1' AND 
fieldname2='fieldvalue2'
        27945 by: Mark Abrams

Mysql and Textarea (Please help me figure out this problem. I' m stuck. Please 
help me!!! )
        27946 by: sam rumaizan
        27947 by: bedul

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
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:[EMAIL PROTECTED] 
Sent: terça-feira, 22 de Maio de 2007 16:07
To: [EMAIL PROTECTED]
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

--- End Message ---
--- Begin Message ---
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:[EMAIL PROTECTED]
Sent: 22 May 2007 05:07
To: [EMAIL PROTECTED]
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

--- End Message ---
--- Begin Message ---
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)"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
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:[EMAIL PROTECTED]
Sent: terça-feira, 22 de Maio de 2007 16:07
To: [EMAIL PROTECTED]
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 

--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
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:

<pre>
<? print_r($_REQUEST) ?>
</pre>

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

--- End Message ---
--- Begin Message ---
Couple of things..  I'm not sure (and too lazy to look it up) if something like 
"category" is a reserved word, but you can try enclosing your field/table names 
in backticks (? whatever they're called.. the single quote looking character on 
the tilde)

SELECT * FROM `classifieds` WHERE `trans_type` = 'For Sale' AND `category` 
='Boats'

or...

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

Making sure your variables always have values.  As mentioned, echoing out your 
$query to see what it translates to can be very useful.

Last thing is to make sure your variables don't contain characters that, 
unescaped, can screw up your query.  Stuff like apostrophes and such.

Best way to do this, and ensure some level of security, is to use 
mysql_real_escape_string().

I don't usually use variables for my field and table names, but I'm guessing 
you can use this function (and that it's recommended to do so anytime you use a 
variable in your SQL) for those as well as values.

$field_name = mysql_real_escape_string($field_name);
$field_name1 = mysql_real_escape_string($field_name1);
$field_value1 = mysql_real_escape_string($field_value1);
$field_name2 = mysql_real_escape_string($field_name2);
$field_value2 = mysql_real_escape_string($field_value2);

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

Or do it inline or write a function wrapper to make it easier to read or 
however you want to do it.


Operation precedence shouldn't be an issue.  I usually run into that when 
dealing with an "OR" situation as well as "AND"s.  Since you have a really 
basic AND-only situation, you shouldn't have to worry about parens.


Maybe that'll help a little.  If not, write back with some of your echo'd SQL 
$query stuff.

-TG





= = = Original message = = =

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)"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
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:[EMAIL PROTECTED]
Sent: ter~a-feira, 22 de Maio de 2007 16:07
To: [EMAIL PROTECTED]
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


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

--- End Message ---
--- Begin Message ---
`` shouldn't react the same as ''.

If it does though, maybe try using them but putting your variables outside the 
quotes:

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


And check what the other poster said about the "SELECT FROM" with no value for 
$field_name.

This is going to be something really simple and basic.

-TG

= = = Original message = = =

Thanks - but it doesn't work   `` interprets the literal value $field_name
as the column name and not its contents "trans_type".

Warning: mysql_query() [http://www.mysql.com/doc]: Unknown column '' in
'field list' in C:\apache2triad\htdocs\sunlakes\test3.php on line 83
Unknown column '' in 'field list'



-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, May 22, 2007 10:57 AM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP-WIN] Query Syntax - WHERE
fieldname1='fieldvalue1'ANDfieldname2='fieldvalue2'

Couple of things..  I'm not sure (and too lazy to look it up) if something
like "category" is a reserved word, but you can try enclosing your
field/table names in backticks (? whatever they're called.. the single quote
looking character on the tilde)

SELECT * FROM `classifieds` WHERE `trans_type` = 'For Sale' AND `category`
='Boats'

or...

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

Making sure your variables always have values.  As mentioned, echoing out
your $query to see what it translates to can be very useful.

Last thing is to make sure your variables don't contain characters that,
unescaped, can screw up your query.  Stuff like apostrophes and such.

Best way to do this, and ensure some level of security, is to use
mysql_real_escape_string().

I don't usually use variables for my field and table names, but I'm guessing
you can use this function (and that it's recommended to do so anytime you
use a variable in your SQL) for those as well as values.

$field_name = mysql_real_escape_string($field_name);
$field_name1 = mysql_real_escape_string($field_name1);
$field_value1 = mysql_real_escape_string($field_value1);
$field_name2 = mysql_real_escape_string($field_name2);
$field_value2 = mysql_real_escape_string($field_value2);

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

Or do it inline or write a function wrapper to make it easier to read or
however you want to do it.


Operation precedence shouldn't be an issue.  I usually run into that when
dealing with an "OR" situation as well as "AND"s.  Since you have a really
basic AND-only situation, you shouldn't have to worry about parens.


Maybe that'll help a little.  If not, write back with some of your echo'd
SQL $query stuff.

-TG



___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

--- End Message ---
--- Begin Message ---
I don't see why you'd have compatibility issues with Excel 2007.  In theory, 
Excel_Writer (which we've used where I work but it's been a while since I've 
messed with it) creates either 97 or 2000 style Excel spreadsheets, which 
should be importable into Excel 2007 with no problem.

I've used the other methods mentioned too and all work well if you have people 
downloading the excel file or viewing in excel via web page.  If you need to 
create an XLS file without downloading via a browser, then you're better off 
trying to get Excel Writer to work, even though it's capabilities are kind of 
limited.

Some people may mention COM, but that's kind of an ugly solution.  You'd need 
Excel installed on the machine you had PHP running on and you gotta be really 
sure you close Excel properly when you're done using it.  If I recall, there's 
a "close" function that only closes the worksheet.  You need to do like 
Application.Exit or maybe it was Quit or something to get it to actally close 
the Excel application.  Otherwise, you'll get a copy of Excel running for each 
time the script is run (server crash anyone?)

Outputting to CSV or HTML with an Excel header, as demonstrated already, are 
good quick and dirty solutions.   Or you can create a page that's an HTML table 
and use Excel's "Import -> Web Query" function to pull the table when you open 
the pre-made Excel spreadsheet and auto-refresh the data from the Web Query.

Good luck however you decide to do it.

-TG

= = = Original message = = =

Using PEAR :: Spreadsheet_Excel_Writer

I am having compatibility issues with Excel 2007.

Has anyone else experienced issues and got solutions?
________________________

Dale Attree

PHP Developer

Jacklin Enterprises

tel: +27 11 265 4282

mobile: +27 83 407 2911
fax: +27 11 314 2984

 

 



***********************************************************************************************
The information contained in this e-mail is confidential and may be subject to 
legal privilege. 
Access to this e-mail by anyone other than the intended recipient is 
unauthorised.

If you are not the intended recipient you must not use, copy, distribute or 
disclose the e-mail or any part of its contents or take any action in reliance 
on it. If you have received this e-mail in error, please notify us immediately 
by e-mail ([EMAIL PROTECTED]) or telephone (+27 11 265 4200).
This message is free of all known viruses. It has been screened for viruses by 
Blockmail.
***********************************************************************************************


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

--- End Message ---
--- Begin Message ---
I've used the COM method some years ago... and it's a mess!

You need to define, create and destroy all objects explicitly... you can't use any "method" for creating the objects, because if you use them, you won't have a reference to the intermediate objects, which will lead to be unable to close excel properlly.

BTW, there are examples out there of COM use... and most don't do things explicitly... and thrus fall in the problem reported...

If it was today... i would run away from using it like plage!

;)

--- End Message ---
--- Begin 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"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> 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:[EMAIL PROTECTED]
> Sent: 22 May 2007 05:07
> To: [EMAIL PROTECTED]
> 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 

--- End Message ---
--- Begin Message ---
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"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> 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:[EMAIL PROTECTED]
> Sent: 22 May 2007 05:07
> To: [EMAIL PROTECTED]
> 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 

--- End Message ---
--- Begin Message ---
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" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> 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 

--- End Message ---
--- Begin Message ---
"SELECT FROM classifieds WHERE trans_type ="For Sale""

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



-----Original Message-----
From: Mark Abrams [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, May 22, 2007 12:48 PM
To: [EMAIL PROTECTED]
Subject: [PHP-WIN] query strings & printouts Re: [PHP-WIN] Query Syntax
- WHERE fieldname1='fieldvalue1' AND fieldname2='fieldvalue2'

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" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> 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

--- End Message ---
--- Begin Message ---
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" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
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


--- End Message ---
--- Begin Message ---
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" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> 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" <[EMAIL PROTECTED]> wrote in message 
>> news:[EMAIL PROTECTED]
>>> 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
>> 

--- End Message ---
--- Begin Message ---
I'm just a php beginner.
  So please be patient with my stupid questions.
   
  What am I missing in this code that causing the function can’t update the 
textarea?
   
  Update button erase the old information from mysql database and replace it 
with nothing. Basically it can’t read what is inside the Textarea box. Why??
   
  Read the highlighted code.
   
  <?php   
include ('./includes/header.html');
include( '../mysql_connect.php' );
  ?>
    </HEAD>
    <BODY>
    <TABLE ALIGN="center" BORDER="0" CELLSPACING="0" CELLPADDING="0">
      <TR ALIGN="center" VALIGN="middle">
        <TH ALIGN="center"><FONT SIZE="6" COLOR ="#310032">View
Existing Data</FONT></TH>
      </TR>
    </TABLE>
      <FORM METHOD="post" ACTION="ved.php">
<?php
$query = "SELECT DISTINCT Assign_Engineer FROM lo_data";
$result = mysql_query($query);
?>
    <BR /><BR />
    <CENTER>
      <SELECT NAME="R"><OPTION VALUE="NULL">Choose a Category:</OPTION>
<?php
while ($line = mysql_fetch_array($result))
{
    foreach ($line as $value)
    {
        echo"<OPTION VALUE='$value'";
    }
    echo ">$value</OPTION>";
}
?>
      </SELECT>
      <INPUT  TYPE="submit" NAME="Submit" VALUE="Submit Data"><BR /><BR
/>
<?php
if (isset($_REQUEST['save_assign_engineer'])) {
    $id = (int) $_REQUEST['save_assign_engineer'];
    $job_title =
mysql_real_escape_string($_REQUEST['Assign_Engineer'][' .$id . ']['Job_Title']);
    $sql = "
        UPDATE `lo_data`
        SET `Job_Title` = '" . $job_title . "'
        WHERE `ID` = " . $id;
    mysql_query($sql);
}
if (isset($_POST["R"])) {
    $result = mysql_query("SELECT * FROM  lo_data WHERE Assign_Engineer 
='".$_POST["R"]."'");
}
?>
      <DIV STYLE="overflow:auto;">
        <TABLE  WIDTH="80" BORDER="1" CELLSPACING="1" CELLPADDING="3"
BORDERCOLOR="CDCB98">
          <THEAD>
            <TR STYLE="position: relative; top:
expression(this.offsetParent.scrollTop); background-color: #CDCB98;">
               <TH>ID</TH>
              <TH>Reference No</TH>
              <TH>Job Descriptions</TH>
              <TH>Category</TH>
              <TH>Assign Engineer</TH>
              <TH>Date Received</TH>
              <TH>Date Required</TH>
              <TH>Date Assigned</TH>
              <TH>Projected Completion Date</TH>
              <TH>Date Completed</TH>
              <TH>Manhour Spent</TH>
              <TH>Status</TH>
            </TR>
          </THEAD>
<?php
$num=mysql_num_rows($result);
echo $num;
while($row = mysql_fetch_array($result))
{
    echo "<TBODY>";
    echo "<TR VALIGN=\"TOP\" ALIGN=\"CENTER\">";
    echo "<TD>{$row['ID']}</TD>";
    echo "<TD>{$row['Ref_No']}</TD>";
    echo '<TD> <P><TEXTAREA NAME="Assign_Engineer[' . $row['ID'] . 
'][Job_Title]" ROWS="10"
    COLS="40">'.$row['Job_Title'] .'</TEXTAREA>';
    echo " <BR />";
echo '<button type="submit" name="save_assign_engineer" value="' .
$row['ID'] . '" />Updaet data</button>
';
    echo "<TD>{$row['Category']}</TD>";
    echo "<TD>{$row['Assign_Engineer']}</TD>";
    echo "<TD>{$row['Date_Received']}</TD>";
    echo "<TD>{$row['Date_Required']}</TD>";
    echo "<TD>{$row['Date_Assigned']}</TD>";
    echo "<TD>{$row['ProjectedCompletionDate']}</TD>";
    echo "<TD>{$row['Date_Completed']}</TD>";
    echo "<TD>{$row['ManhourSpent']}</TD>";
    echo "<TD>{$row['Status']}</TD>";
    echo "</TR>";
    echo"</TBODY>";
}
  ?>





       
---------------------------------
Sick sense of humor? Visit Yahoo! TV's Comedy with an Edge to see what's on, 
when. 

--- End Message ---
--- Begin Message ---
use $_POST[your var] in this script..
not simple but worked..

other option

$_HTTP_POST_VARS[your var]


----- Original Message -----
From: "sam rumaizan" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, May 23, 2007 4:13 AM
Subject: [PHP-WIN] Mysql and Textarea (Please help me figure out this
problem. I' m stuck. Please help me!!! )


> I'm just a php beginner.
>   So please be patient with my stupid questions.
>
>   What am I missing in this code that causing the function can't update
the textarea?
>
>   Update button erase the old information from mysql database and replace
it with nothing. Basically it can't read what is inside the Textarea box.
Why??
>
>   Read the highlighted code.
>
>   <?php
> include ('./includes/header.html');
> include( '../mysql_connect.php' );
>   ?>
>     </HEAD>
>     <BODY>
>     <TABLE ALIGN="center" BORDER="0" CELLSPACING="0" CELLPADDING="0">
>       <TR ALIGN="center" VALIGN="middle">
>         <TH ALIGN="center"><FONT SIZE="6" COLOR ="#310032">View
> Existing Data</FONT></TH>
>       </TR>
>     </TABLE>
>       <FORM METHOD="post" ACTION="ved.php">
> <?php
> $query = "SELECT DISTINCT Assign_Engineer FROM lo_data";
> $result = mysql_query($query);
> ?>
>     <BR /><BR />
>     <CENTER>
>       <SELECT NAME="R"><OPTION VALUE="NULL">Choose a Category:</OPTION>
> <?php
> while ($line = mysql_fetch_array($result))
> {
>     foreach ($line as $value)
>     {
>         echo"<OPTION VALUE='$value'";
>     }
>     echo ">$value</OPTION>";
> }
> ?>
>       </SELECT>
>       <INPUT  TYPE="submit" NAME="Submit" VALUE="Submit Data"><BR /><BR
> />
> <?php
> if (isset($_REQUEST['save_assign_engineer'])) {
>     $id = (int) $_REQUEST['save_assign_engineer'];
>     $job_title =
> mysql_real_escape_string($_REQUEST['Assign_Engineer'][' .$id .
']['Job_Title']);
>     $sql = "
>         UPDATE `lo_data`
>         SET `Job_Title` = '" . $job_title . "'
>         WHERE `ID` = " . $id;
>     mysql_query($sql);
> }
> if (isset($_POST["R"])) {
>     $result = mysql_query("SELECT * FROM  lo_data WHERE Assign_Engineer
='".$_POST["R"]."'");
> }
> ?>
>       <DIV STYLE="overflow:auto;">
>         <TABLE  WIDTH="80" BORDER="1" CELLSPACING="1" CELLPADDING="3"
> BORDERCOLOR="CDCB98">
>           <THEAD>
>             <TR STYLE="position: relative; top:
> expression(this.offsetParent.scrollTop); background-color: #CDCB98;">
>                <TH>ID</TH>
>               <TH>Reference No</TH>
>               <TH>Job Descriptions</TH>
>               <TH>Category</TH>
>               <TH>Assign Engineer</TH>
>               <TH>Date Received</TH>
>               <TH>Date Required</TH>
>               <TH>Date Assigned</TH>
>               <TH>Projected Completion Date</TH>
>               <TH>Date Completed</TH>
>               <TH>Manhour Spent</TH>
>               <TH>Status</TH>
>             </TR>
>           </THEAD>
> <?php
> $num=mysql_num_rows($result);
> echo $num;
> while($row = mysql_fetch_array($result))
> {
>     echo "<TBODY>";
>     echo "<TR VALIGN=\"TOP\" ALIGN=\"CENTER\">";
>     echo "<TD>{$row['ID']}</TD>";
>     echo "<TD>{$row['Ref_No']}</TD>";
>     echo '<TD> <P><TEXTAREA NAME="Assign_Engineer[' . $row['ID'] .
'][Job_Title]" ROWS="10"
>     COLS="40">'.$row['Job_Title'] .'</TEXTAREA>';
>     echo " <BR />";
> echo '<button type="submit" name="save_assign_engineer" value="' .
> $row['ID'] . '" />Updaet data</button>
> ';
>     echo "<TD>{$row['Category']}</TD>";
>     echo "<TD>{$row['Assign_Engineer']}</TD>";
>     echo "<TD>{$row['Date_Received']}</TD>";
>     echo "<TD>{$row['Date_Required']}</TD>";
>     echo "<TD>{$row['Date_Assigned']}</TD>";
>     echo "<TD>{$row['ProjectedCompletionDate']}</TD>";
>     echo "<TD>{$row['Date_Completed']}</TD>";
>     echo "<TD>{$row['ManhourSpent']}</TD>";
>     echo "<TD>{$row['Status']}</TD>";
>     echo "</TR>";
>     echo"</TBODY>";
> }
>   ?>
>
>
>
>
>
>
> ---------------------------------
> Sick sense of humor? Visit Yahoo! TV's Comedy with an Edge to see what's
on, when.

--- End Message ---

Reply via email to