Jump to content

My query isnt working!


thefollower

Recommended Posts

I had to alter my query to get the table names matching mine but it suddenly says its got a syntax error but isnt telling me where. Its quite a complex query (for my standards) so was wondering if any one could spot where i went wrong:

 

$GetHouses = mysql_query("SELECT houses.*, cities.*, countries.* FROM houses, cities, countries 
		WHERE houses.userID ='{$_SESSION['Current_User']}' AND cities.cityID = houses.cityID AND cities.countryID = countries.countryID.")
		or die(mysql_error());

 

 

also are names of tables/fields case sensitive ?

 

Link to comment
https://forums.phpfreaks.com/topic/66505-my-query-isnt-working/
Share on other sites

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 2

 

 

thats all it says.

 

I have corrected my code to make it match with case and same problem arises. I read the manual but they always seem to be different and less complex queries so Im never sure if theres something that i need to add or take away cos it could be different when using so many tables...

Link to comment
https://forums.phpfreaks.com/topic/66505-my-query-isnt-working/#findComment-333055
Share on other sites

Try this:

$userID = $_SESSION['Current_User'];
$sql = "SELECT houses.*, cities.*, countries.* FROM houses, cities, countries WHERE houses.userID = $userID AND cities.cityID = houses.cityID AND cities.countryID = countries.countryID";
$GetHouses = mysql_query($sql) or die(mysql_error().' - '.$sql);

 

Right off the bat I see you had a . at the end of your SQL query, that might have freaked it out ;)

Don't try to do everything in one line, it's okay to have 3 lines if it makes it less confusing. Easier to debug and maintain!

Link to comment
https://forums.phpfreaks.com/topic/66505-my-query-isnt-working/#findComment-333060
Share on other sites

Your right it was the . symbol.

 

 

But i get this:

 

Houses Not found!

 

thats to do with something i put encase it doesnt work :

 

$GetHouses = mysql_query("SELECT houses.*, cities.*, countries.* FROM houses, cities, countries 
		WHERE houses.UserID ='{$_SESSION['Current_User']}' AND cities.CityID = houses.CityID AND cities.CountryID = countries.CountryID")
		or die(mysql_error());
// Fetch the row from the database
if (!($gethouserow = mysql_fetch_assoc($GetHouses))) {
    echo "Houses Not found!";
    exit;
}

Link to comment
https://forums.phpfreaks.com/topic/66505-my-query-isnt-working/#findComment-333065
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.