Sql Query with PHP, need Help
Moderator: General Moderators
Sql Query with PHP, need Help
Hey thanks for taking a look, I am trying to to access data through a form and i am incountering a couple problems. This is the error i am getting:
"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 'SELECT sa.AgencyID FROM AgencyAreas aa"
here is the code for the query:
$result = mysql_query("SELECT ag.AgencyID, ag.CompanyName, ag.Address, ag.StateOrProvince, ag.City, ag.PostalCode
FROM Agencies ag
WHERE ag.StateOrProvince ='$province'
AND ag.AgencyID IN ( SELECT sa.AgencyID
FROM AgencyAreas aa
INNER JOIN Areas ar ON (aa.AreaServedID=
ar.AreaServedID)
WHERE a.AreaServed LIKE '%$city')
AND ag.AgencyID IN ( SELECT as.AgencyID
FROM AgencyServices
WHERE ServiceID IN ($services))"
) or die("Invalid query: " . mysql_error() );
// $services is a check box array
what i am trying to do is to get the relevent information based on the area the agency served based on a text field search and services provided based on a check box query. I hope this makes sense, if not sorry my brain is mush right now. Thanks again
"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 'SELECT sa.AgencyID FROM AgencyAreas aa"
here is the code for the query:
$result = mysql_query("SELECT ag.AgencyID, ag.CompanyName, ag.Address, ag.StateOrProvince, ag.City, ag.PostalCode
FROM Agencies ag
WHERE ag.StateOrProvince ='$province'
AND ag.AgencyID IN ( SELECT sa.AgencyID
FROM AgencyAreas aa
INNER JOIN Areas ar ON (aa.AreaServedID=
ar.AreaServedID)
WHERE a.AreaServed LIKE '%$city')
AND ag.AgencyID IN ( SELECT as.AgencyID
FROM AgencyServices
WHERE ServiceID IN ($services))"
) or die("Invalid query: " . mysql_error() );
// $services is a check box array
what i am trying to do is to get the relevent information based on the area the agency served based on a text field search and services provided based on a check box query. I hope this makes sense, if not sorry my brain is mush right now. Thanks again
-
tylerdurden
- Forum Commoner
- Posts: 66
- Joined: Mon Jul 28, 2003 11:52 am
- Location: Austria
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Re: brackets
Not if you're setting aliases -Whil wrote:from [ag agencies]
if you have 2 words (spaces) you normally have to have the table / field name in [] ...
hope this helps you out.
Code: Select all
FROM Agencies agCode: Select all
FROM Agencies AS ag