[SGVLUG] A puzzling PHP / MySQL problem.
Peter Fogg
peter.fogg at sbcglobal.net
Thu Feb 1 10:57:33 PST 2007
These are the first four data that are handled in a set of fifteen data
submitted by the form. I have left the others off because they are
commented out of my code at the moment.
$whereString = '';
// category and sub-category
if ($_REQUEST['eventCategory'] > 0)
{
$whereString = 'eventType = ' . $_REQUEST['eventCategory'] . '
AND eventSubtype = ' . $_REQUEST['eventSubCategory'];
}
else
{
// nada
}
// website
if (!empty($whereString) && !empty($_REQUEST['website']))
{
$whereString .= ' AND website LIKE \'%' . $_REQUEST['website'] .
'%\'';
}
elseif (!empty($_REQUEST['website']))
{
$whereString = 'website LIKE \'%' . $_REQUEST['website'] . '%\'';
}
else
{
// nada
}
// title
if (!empty($whereString) && !empty($_REQUEST['title']))
{
$whereString .= ' AND title LIKE \'%' . $_REQUEST['title'] .
'%\'';
}
elseif (!empty($_REQUEST['title']))
{
$whereString = 'title LIKE \'%' . $_REQUEST['title'] . '%\'';
}
else
{
// nada
}
This variable is populated later in the code but does not become
involved in this scenario.
$cityStateZipQueryString = '';
This code builds the query string:
if (!empty($cityStateZipQueryString) || !empty($whereString))
{
$quickSearchQuery = 'SELECT eventID, venueID, title, summary,
eventType, eventSubtype, eventStartDate, eventStartTime, admissionPrice
FROM events WHERE ';
if (!empty($whereString) && !empty($cityStateZipQueryString))
{
$quickSearchQuery .= ' (' . $whereString . ') AND venueID IN
(SELECT venueID FROM venues WHERE ' . $cityStateZipQueryString . ')';
}
elseif (empty($whereString))
{
$quickSearchQuery .= ' venueID IN (SELECT venueID FROM venues
WHERE ' . $cityStateZipQueryString . ')';
}
elseif (empty($cityStateZipQueryString))
{
$quickSearchQuery .= ' (' .$whereString . ') ';
}
$quickSearchQuery .= ' ORDER BY title ASC';
echo $quickSearchQuery . '<br /><br />';
$DBConnection = new connection;
$arrayQSResult = mysql_query($quickSearchQuery,
$DBConnection->dbcon) or die('ERROR 1: ' . mysql_error() . '.');
If I enter a title alone or a title and a Website, I get the error
message. If I enter the website alone, ok. If I enter an event category
(the event sub-category is automatically included) and either or both
title and website or none, ok.
Peter -
On Feb 1, 2007, at 10:31 AM, Stan Schwarz wrote:
>> Yes, see my post a little earlier today.
>
> I see the PHP that puts the SQL together, but not the line where
> it gets executed. That's what I want to see.
>
>> On Feb 1, 2007, at 10:03 AM, Stan Schwarz wrote:
>>
>>>> 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.
>>>
>>> I've seen this before. Can you post the snippet of PHP where
>>> you actually do the query?
>>>
>>>
>>> --
>>> -----------------------------------------------------------------
>>> Stan Schwarz |"Sun likely will have to embrace Linux
>>> stan at iron.gps.caltech.edu | and eat their own children, or watch
>>> | IBM and HP do it instead." - crn.com
>>> - http://pasadena.wr.usgs.gov/stans -----------------------------
>>>
>>
>>
>
>
> --
> -----------------------------------------------------------------
> Stan Schwarz |"Sun likely will have to embrace Linux
> stan at iron.gps.caltech.edu | and eat their own children, or watch
> | IBM and HP do it instead." - crn.com
> - http://pasadena.wr.usgs.gov/stans -----------------------------
>
More information about the SGVLUG
mailing list