1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| if($saveMote){
#save the new mote information into the database.
if(!$conn){
die("Could not connect to database server!<br />");
} else {
$query = "SELECT * FROM $table WHERE miid=$miid";
$result = pg_query($query);
$meta = pg_meta_data($conn, $table);
$query = "UPDATE $table SET";
if (is_array($meta)){
// for every field
$count = 0;
foreach(array_keys($meta) as $field){
echo "$field,\n ";
//take the longitude_dms and latitude_dms for check purpose before querying(awal_start)
if (strcmp($field,"longitude_dms")==0){
$local_longitude=stripslashes($_POST[$field]);
var_dump($_POST[$field]);
//echo "local_longitude = ".stripslashes($local_longitude);//add
echo " ".strcmp($field,"longitude_dms")." ";//add
}
else if (strcmp($field,"longitude_dms")==0){
$local_latitude = $_POST[$field];
echo " ".strcmp($field,"latitude_dms")." ";//add
}
//end take (awal_end)
$type = $meta[$field]["type"];
if(($type=="int4") || ($type=="numeric")){
if ($_POST[$field]){
if($count != 0){
$query .= ",";
}
$query .= " $field=".$_POST[$field];
}
} else if($type == "varchar"){
if($count != 0){
$query .= ",";
}
$query .= " $field='".$_POST[$field]."'";
} else if($type == "timestamp") {
if($count != 0){
$query .= ",";
}
if($_POST[$field] != ""){
$query .= " $field='".$_POST[$field]."'";
} else {
$query .= " $field=now()";
}
}
$count += 1;
}
}
$query .= " WHERE miid=$miid";
echo $query;
echo "local longitude = ".$local_longitude;
//verify the pattern matching before querying (awal_start)
#$pattern ="/(\d+)°(\d+)\'(\d+)\"/";
//$local_longitude = stripslashes($local_longitude);//remove anti-
//$local_longitude = "25°33'23\"";
//$local_longitude = stripslashes($local_longitude);
echo "valeur de retour de preg_match : ".preg_match("/([0-9]+)°([0-9]+)'([0-9]+)\"/",$local_longitude);
if (preg_match("/([0-9]+)°([0-9]+)'([0-9]+)\"/",$local_longitude)){ //correct format was entered
$res = pg_query($query);
// show the new mote data
showmotes($table, $conn, $clusterid);
}
else
{
echo "latitude and longitude must have the following format x°y'z";
} |
Partager