Figured it out. Here is the code:
$( "#cow" ).draggable({ revert: true});
$( "#map" ).droppable({
drop: function( event, ui ) {
var farmid = 448;
var point = map.getLonLatFromPixel( map.events.getMousePosition(event, ui ) )
var lon = point.lon.toFixed(3);
var lat = point.lat.toFixed(3);
var dropPosition = point.lon.toFixed(3) + ' ' + point.lat.toFixed(3);
$.ajax({
type: "GET",
url: "../php/position.php",
contentType: "application/json; charset=utf-8",
data: "{'farmid':'"+ farmid +"', 'position':'"+ dropPosition +"'}",
success: function(returnval){
var pid = parseInt(returnval);
var selectB = new OpenLayers.Control.SelectFeature([farmbounds]);
for(var f=0;f<farmbounds.features.length;f++) {
if(farmbounds.features[f].fid == 'farmpaddocks.'+pid+'') {
selectB.select(farmbounds.features[f]);
break;
}}
}//success
});//ajax
}
});
And the php file looks like this:
<?php
$farmid= $_GET["farmid"];
$position = $_GET["position"];
$db = pg_connect("host=localhost dbname=postgis user=aaaaa password=bbbbb" );
$sql = "SELECT * FROM public.farmpaddocks WHERE farmid = '$farmid' AND st_contains(farmpaddocks.the_geom,ST_GeomFromText('POINT($position)',3111)) ='t'";
$resultD = pg_query($db,$sql);
while($rowD=pg_fetch_row($resultD))
{
$paddockid= $rowD[0];
echo $paddockid;
}
?>