Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.