[SGVLUG] A puzzling PHP / MySQL problem.

Peter Fogg peter.fogg at sbcglobal.net
Thu Feb 1 09:35:47 PST 2007


Yes, the line in my original post that begins with "SELECT" is an echo 
of the query string.

The echoed query string is built on the fly in response to data entered 
in an html page. This is the PHP code which creates the query string: 
(eventCategory and eventSubCategory are integers, title and website are 
strings)

   // category and sub-category
     if ($_REQUEST['eventCategory'] > 0)
     {
       $whereString = 'eventType = ' . $_REQUEST['eventCategory'] . ' 
AND eventSubtype = ' . $_REQUEST['eventSubCategory'];
     }

   // title
     if (isset($whereString) && !empty($_REQUEST['title']))
     {
       $whereString .= ' AND title LIKE \'%' . $_REQUEST['title'] . 
'%\'';
     }
     elseif (!empty($_REQUEST['title']))
     {
       $whereString = 'title LIKE \'%' . trim($_REQUEST['title']) . 
'%\'';
     }

   // website
     if (isset($whereString) && !empty($_REQUEST['website']))
     {
       $whereString .= ' AND website LIKE \'%' . $_REQUEST['website'] . 
'%\'';
     }
     elseif (!empty($_REQUEST['website']))
     {
       $whereString = 'website LIKE \'%' . $_REQUEST['website'] . '%\'';
     }

If any combination of eventCategory (eventSubCategory is automatically 
present when an event category is chosen), title and website, except in 
one instance, a query string that works is generated. The one exception 
is if only the website value is entered, the error below is the result.


On Jan 31, 2007, at 7:50 PM, Matthew Gallizzi wrote:

> Peter,
>
> It sounds like PHP is the problem here... that query should be 
> working. Have you tried to echo when you run the query to see if 
> something funny is happening with the quotes?
>
>  On 1/31/07, Peter Fogg <peter.fogg at sbcglobal.net> wrote:
>>
>> The following query results in a mysql error if executed by PHP but
>> succeeds if entered into the SQL window of phpMyAdmin:
>>
>> SELECT eventID, venueID, title, summary, eventType, eventSubtype,
>> eventStartDate, eventStartTime, admissionPrice FROM events WHERE 
>> (website
>> LIKE '%a%') ORDER BY title ASC
>>
>> ERROR 1: 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 '' at line 1.
>>
>> The server is an iMac OS 10.3.9, MySQL 5.0.16-standard, PHP Version
>> 5.0.4.
>>
>> Peter -
>>
>
>
>
> -- 
> Matthew Gallizzi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 2391 bytes
Desc: not available
Url : http://www.sgvlug.net/pipermail/sgvlug/attachments/20070201/971b9e43/attachment.bin


More information about the SGVLUG mailing list