for the "mysql_query($sql, $link) or die("OOPS!")" line, what is the $link for?
Main Topics
Browse All TopicsHey 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 when i pass it to the php script:
"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
My second problem is that $services is an array from check boxes and i have no clue how to include it in the query, WHERE ServiceID IN ($services))" just seems way to easy for the luck i have been having with this.
what i am trying to do is to return information based on the areas the agency serves based on a text field input from the user 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
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
$link is the connection to the mysql server. It is some kind of pointer. It points to the mysql connection.
use
$link = mysql_connect("server:port
to connect to the server.
If you have only one connection it will take that connection by default.
But if you have more than one it will use the connection specified.
Business Accounts
Answer for Membership
by: pizzametsalamiPosted on 2003-07-29 at 06:38:52ID: 9027871
You might want to place a comma between the two tables from which you read; like:
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));
That would get you closer.
The $services array is a harder part.
$sql = "You might want to place a comma between the two tables from which you read; like:
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 ";
for ($i=0; $i<count($services); $i++)
{
if ($i>0)
$sql.= " AND ";
$sql.= "ServiceId IN (" & $services[$i] & ")";
}
$sql.=");"
mysql_query($sql, $link) or die("OOPS!")
I think this will help you out. Good Luck!