Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8578991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:31:04+00:00 2026-06-11T20:31:04+00:00

The following SQL query works perfectly fine when I run it with PHPMyAdmin but

  • 0

The following SQL query works perfectly fine when I run it with PHPMyAdmin but when I run it from a web page I get an error. I have looked around on StackOverflow for similar questions and have tried their suggestions but alas… Does anyone have an idea why it won’t work on the web page?

The SQL query after variables have been put in (example):

SELECT place FROM locations WHERE (( 69.1 * ( latitude - 51.4700000 ) ) * ( 69.1 * (latitude - 51.4700000 ) )) + ( ( 69.1 * ( longitude - 5.5528000 ) * COS( 51.4700000 / 57.3 )) * ( 69.1 * ( longitude - 5.5528000 ) * COS( 51.4700000 / 57.3 ) ) ) < 976.5625 ORDER BY ((69.1 * ( latitude - 51.4700000 ) ) * ( 69.1 * ( latitude - 51.4700000 ) )) + ( ( 69.1 * ( longitude - 5.5528000 ) * COS( 51.4700000 / 57.3 ) ) * ( 69.1 * ( longitude - 5.5528000 ) * COS(51.4700000 / 57.3 ) ) ) ASC

The PHP ($radius and $start are defined a little before this):

$latitude = $start['latitude'];
$longitude = $start['longitude'];
$r = pow($radius, 2);
$inrange = "SELECT place FROM locations_2 WHERE ((69.1 * (latitude - $latitude)) * (69.1 * (latitude - $latitude))) + ((69.1 * (longitude - $longitude) * COS($latitude / 57.3)) * (69.1 * (longitude - $longitude) * COS($latitude / 57.3))) < $r ORDER BY ((69.1 * (latitude - $latitude)) * (69.1 * (latitude - $latitude))) + ((69.1 * (longitude - $longitude) * COS($latitude / 57.3)) * (69.1 * (longitude - $longitude) * COS($latitude / 57.3))) ASC";
$result = mysql_query($inrange) or die(mysql_error());

The error message I get is:

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 ')) * (69.1 * (`latitude` - ))) + ((69.1 * (`longitude` - ) * COS( / 57.3)) * (69' at line 1

What’s even stranger is that it worked… I wrote it all down, just the way I’m presenting it to you now, and was happy to see it worked just fine. That was earlier today. Now an hour or so ago I tried it again and for some reason it stopped working. I truly don’t remember changing a thing.

EDIT

Thanks everyone. I figured it out and it turned out I made a stupid mistake. It worked earlier today because all the users had their location set. Now, I have a few users that don’t so while looping through them the longitude and latitude came up empty.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:31:05+00:00Added an answer on June 11, 2026 at 8:31 pm

    From your error message it seems like $latitude and $longitude does not contain any values. You probably want to check that $start is properly set. This is all I can help you with since I do not know what $start is and how you’re getting it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have following sql query, everything works fine but when i put and posted_date<>$datetime
I have the following which works in SQL Query Analyzer . select oh.* from
The following sql query works fine on my development server running mysql 5, but
I have the following SQL query that works like a champ: select u.id from
If I run the following SQL query SELECT * FROM A LEFT JOIN B
I have the following SQL query I was given, but I am not sure
I have following SQL query SELECT TOP 10000 AVG(DailyNodeAvailability.Availability) AS AVERAGE_of_Availability FROM Nodes INNER
I have the following SQL Server query and I am trying to get the
I have the following SQL Server 2008 query that works for all of my
I have the following SQL query in oracle: SELECT * FROM ( SELECT s.singleid,s.titel,a.naam,s.taal,SUM(b.aantal)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.