Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Proper query punction for var


Message #1 by Jefferis Peterson <jefferis@p...> on Tue, 17 Sep 2002 15:44:30 -0400
In PHP you don't need to concatenate your strings that way. There is a user
contributed note at the bottom of this page:
http://www.php.net/manual/en/function.mysql-query.php
giving an example showing just that. In PHP
$query = "SELECT * FROM MYTable WHERE ID = $ID"
is the same as
$query = "SELECT * FROM MYTable WHERE ID = " . $ID (. being the string
concetenation operator)

The problem may be that the "name" is a reserved keyword for MySQL. Either
way the best way to check an SQL Statement is to do a screen dump and check
it. echo your SQL String to the page and stop the execution of your page at
that point. I don't know the equivalent of the asp method Response.End, but
you want something like that. Then check the SQL String in whatever client
tool you use to access your database. 

regards
David Cameron
nOw.b2b
dcameron@i...

> -----Original Message-----
> From: Brian Freeman [mailto:freeman@C...]
> Sent: Wednesday, 18 September 2002 6:37 AM
> To: sql language
> Subject: [sql_language] RE: Proper query punction for var
> 
> 
> I'm no expert in PHP, but I believe you need to concatenate the string
> similar to this: 
> $strSQL="select * from Catalog where descrip LIKE '%" & 
> $keysubmit & "%'
> order by name" and then have the call:
> $Search = WrapMySQLDatabaseResults("localjoden", $strSQL,
> "block=0","Search");
> 
> Check what your string concatenation operator is (+ or & etc).  The
> additional "%" are to match the keyword any where in the 
> field (like 'word'
> will only match if "word" is the only thing in the field, 
> like 'word%' will
> only match where "word" is the first thing (i.e. "word", 
> "word of the week"
> but not "my word") and '%word%" matches if word is anywhere 
> in the field
> (i.e. matches all stated plus "my word", "the last word word" 
> "words" etc).
> Alternately embed the concatenation in the call, but you will need to
> concatenate.  
> 
> I think your sql is ending up as
> select * from Catalog where descrip LIKE '$keysubmit' order by name
> 
> Instead of using the value of the $keysubmit variable.
> 
> Just for reference the final SQL should read like (if
> $keysubmit="userword"):
> select * from Catalog where descrip LIKE '%userword%' order by name
> 
> Hope this helps.
> 
> Brian Freeman
>  (xxx) xxx-xxxx  ext. 415
> Carnegie Technologies/Bluewave Computing 
> www.carnegie.com and www.bluewave-computing.com
> 
> -----Original Message-----
> From: Jefferis Peterson [mailto:jefferis@p...]
> Sent: Tuesday, September 17, 2002 3:45 PM
> To: sql language
> Subject: [sql_language] Proper query punction for var
> 
> 
> I'm getting a parse error in the following page trying to 
> create a keyword
> search from a form with a fieldname "keysubmit"
> 
> I am wondering if my search query following LIKE is the proper syntax.
> Jeff
> 
> > <php?
> > var keysubmit = $keysubmit;
> > ?>
> > 
> > <html>
> > <head>
> > <title>Untitled Document</title>
> >       <meta http-equiv="Content-Type" content="text/html;
> charset=iso-8859-1">
> >       <?php // GoLive Content Source
> >          $Search = WrapMySQLDatabaseResults("localjoden", 
> "select * from
> > Catalog where descrip LIKE '$keysubmit' order by name",
> "block=0","Search");
> >       ?>
> >   </head>
> > ~~~~~~~~~~~~
> Jefferis Peterson, Pres.
> Web Design and Marketing
> http://www.PetersonSales.net
> Tel .  xxx-xxx-xxxx
> ICQ 19112253
> 
> http://www.Slippery-Rock.com - 7,000 hits per year
> 
> 
> 
> 
> 


  Return to Index