loadExtension('libspatialite.so'); # read data from the form $name=pg_escape_string($_POST["uname"]); $istitute=pg_escape_string($_POST["iname"]); $lat=$_POST["lat"]; $long=$_POST["long"]; # some check if ($name == "test" or $istitute == "test"){ exit("{success: false, errors: {reason: 'It is not possible to use \'test\' as value'}}"); } else if ($name == $istitute){ exit("{success: false, errors: {reason: 'Values for user and institute may not be the same'}}"); } # try to load data on spatialite database try { $grassuserdb->exec("INSERT INTO users (name, company, x, y, data_insert) VALUES ('$name', '$istitute', $long, $lat, datetime('now'))"); } catch (Exception $e) { exit("{success: false, errors: {reason: 'Error during insert; $e'}}"); } # update geometry column $grassuserdb->exec("update users set geom = GeomFromText('POINT(' || x ||' '|| y || ')',4326)"); $grassuserdb->close(); echo "{success: true}"; ?>