<?php

require_once('db_locations.php');
require_once(
'JSON.php'); // http://pear.php.net/pepr/pepr-proposal-show.php?id=198
$json = new Services_JSON();
$type = isset($_POST['type']) ? $_POST['type'] : '';
if(
$type == 'upload') {
    
$name      = isset($_POST['name'])      ? addslashes($_POST['name'])  : '';
    
$latitude  = isset($_POST['latitude'])  ? (1.0 $_POST['latitude'])  : 0;
    
$longitude = isset($_POST['longitude']) ? (1.0 $_POST['longitude']) : 0;
    
    
$sql "INSERT INTO jquery_locations (name,latitude,longitude,created) VALUES ('$name',$latitude,$longitude,NOW())";
    
mysql_query($sql);
}

$locations = array();
$result mysql_query('SELECT name, latitude, longitude, created FROM jquery_locations ORDER BY created DESC LIMIT 10');
while(
$row mysql_fetch_array($result)) {
    
$locations[] = $row;
    
$oldest_date $row['created'];
}

mysql_query("DELETE FROM jquery_locations WHERE created<'$oldest_date'");
echo 
$json->encode($locations);
?>