Re: Quoted Dynamic Strings are killing me (Second Attempt)
| From: | DL Neil | Date: | Mon, 22 Apr 2002 14:59:28 +0000 |
| Subject: | Re: Quoted Dynamic Strings are killing me (Second Attempt) | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-13229@lists.php.net to get a copy of this message | ||
Ron,
> I have been trying to create strings dynamically by combining text and
> variables. Because SQL wants single quotes surrounding the values I
> have been forced to create the string as follows (all variables have
> been previuosly set earlier on the page):
>
> $query = "select bio FROM individual WHERE last_name ='".
> $selectedLastname ."' AND first_name ='". $selectedFirstname ."'
> AND
market
> ='".$selectedMarket."'";
>
> Which seems to be good to me but when I echo the query it parses out
> like this:
>
> select bio FROM individual WHERE last_name ='Appleyard
> selectedFirstname=Peter selectedMarket=Atlanta' AND first_name ='' AND
> market =''
>
> What am I missing...or doing wrong? This seems so straightforward but
> I'm getting beat up something horrible!
Looks like a confusion of quotation marks (v.difficult to see on
email/some fonts).
Remember that string variables within double quotes are evaluated:
take out all the double-quotes except the first and last, and remove all
the . (concatenation) operators.
Now review the remaining single quotes, with regard to SQL's rules for
quoting string values.
(in review: double quotes for PHP, single quotes for SQL)
OK now?
=dn