thefollower Posted August 24, 2007 Share Posted August 24, 2007 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/66505-my-query-isnt-working/ Share on other sites More sharing options...
Jessica Posted August 24, 2007 Share Posted August 24, 2007 Can you show us the error, and yes, they are. Quote Link to comment https://forums.phpfreaks.com/topic/66505-my-query-isnt-working/#findComment-333042 Share on other sites More sharing options...
thefollower Posted August 24, 2007 Author Share Posted August 24, 2007 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... Quote Link to comment https://forums.phpfreaks.com/topic/66505-my-query-isnt-working/#findComment-333055 Share on other sites More sharing options...
Jessica Posted August 24, 2007 Share Posted August 24, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/66505-my-query-isnt-working/#findComment-333060 Share on other sites More sharing options...
thefollower Posted August 24, 2007 Author Share Posted August 24, 2007 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; } Quote Link to comment https://forums.phpfreaks.com/topic/66505-my-query-isnt-working/#findComment-333065 Share on other sites More sharing options...
beboo002 Posted August 25, 2007 Share Posted August 25, 2007 put this code ' ".$_SESSION['Current_User']. " ' insted of this '{$_SESSION['Current_User']}' try it may help u Quote Link to comment https://forums.phpfreaks.com/topic/66505-my-query-isnt-working/#findComment-333761 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.