I have a POSTGIS database with a table "space" that has two columns "id" and "geometry".
I also have a PHP script that accesses the database and returns data. My program is running on mobile devices and delivers the id and a location. I now try to figure out if the table "space" does have an entry with the given id and if so, if the user is within the boundaries of the geometry in "geometry".
This is my code:
$id = $_POST['id']; $lon = $_POST['lon']; $lat = $_POST['lat']; $statementCheck = $pdo->prepare("SELECT * FROM space WHERE id= :id AND ST_Within(ST_MakePoint($long, $lat), geometry)"); $statementCheck->bindParam(':id', $id, PDO::PARAM_STR); $statementCheck->execute();
My problem is:
$statementCheck->execute() returns false. However, I'm sure that there is a matching dataset in the table. Am I using ST_Within in a wrong way? The tutorials I looked at suggest that this is the way to do it. I'm a bit suspecting the ",geometry" part of ST_MakePoint to be not accurate.
edit: Fixed typing error.