#print "$id $number texted: $message\n<p>\n";
    if ($number != '' && $message != '') {
        $date = date("Y-m-d H:i:s");
        $sql = "INSERT INTO location (latitude, longitude, location_name, location_date) ";
        $sql .= "VALUES('30.297017883372', '69.89501953125', '{$unknown_loc}', '{$date}') ;";
        $resl = mysql_query($sql);
        $loc_id = DBQuery::get_last_id();
        if (!$loc_id) {
            print "Could not add default location!";
            continue;
        }
        $sql = "INSERT INTO incident (incident_title, incident_mode, incident_dateadd, incident_date, location_id) ";
        $sql .= "VALUES ('" . mysql_real_escape_string($message) . "', '2', '{$date}', '{$date}', '{$loc_id}');";
        $ins = mysql_query($sql);
        print "<p>\n{$sql}\n<p>\n";
        $idIncident = DBQuery::get_last_id();
        if ($idIncident != '' && $ins) {
            #add phone number
            $sql = "INSERT INTO form_response (form_field_id, incident_id, form_response) VALUES ('1', '{$idIncident}', '" . mysql_real_escape_string($number) . "');";
            $ins = mysql_query($sql);
            print "<p>\n{$sql}\n<p>\n";
            $sql = "INSERT INTO incident_automated (idIncident, idMessage, status) VALUES ('{$idIncident}', '{$id}', 0);";
            $ins = mysql_query($sql);
            print "<p>\n{$sql}\n<p>\n";
        } else {
            print "\n<p>Error! Could not insert<p>\n";
        }
    }
}
//die;
/// SECOND, GET ALL INCIDENTS
        $latitude = $worker_lat;
    }
    if ($longitude == 0 && $worker_long != '' && $worker_long != 0) {
        $longitude = $worker_long;
    }
}
$description = implode("\n", $translations) . "\n\nNotes:\n" . implode("\n", $notes);
$location_name = implode("  ", array_unique($locationnames));
$latitude = preg_replace("/[^0-9\\-\\.]/", "", $latitude);
$longitude = preg_replace("/[^0-9\\-\\.]/", "", $longitude);
$loc_id = "";
if ($latitude != '' && $longitude != '') {
    $sql = "INSERT INTO location (latitude, longitude, location_name, location_date) ";
    $sql .= "VALUES('{$latitude}', '{$longitude}', '" . mysql_real_escape_string($location_name) . "', '" . date("Y-m-d H:i:s") . "') ;";
    $res = mysql_query($sql);
    $loc_id = DBQuery::get_last_id();
    print "\nnew loc_id = {$loc_id}\n";
}
$sql = "UPDATE incident SET incident_description = '" . mysql_real_escape_string($description) . "'";
if ($loc_id != '') {
    $sql .= ", location_id = '{$loc_id}' ";
}
$sql .= " WHERE id = '{$id}' ; ";
if (preg_match('/WHERE id....[0-9]/', $sql)) {
    #preg match as a sanity check to make sure we are only updating one record inthe main incident table
    $res = mysql_query($sql);
    print "<p>\nUPDATED incident={$id}\n<p>";
}
foreach ($categories as $category) {
    $catd = preg_split('/\\|/', $category);
    $parent = trim($catd[0]);
 /**
  * Updates the
  *
  */
 public static function update($db_fields, $table_name, $pk_name = '')
 {
     if ($pk_name == '') {
         $pk_name = 'id' . $table_name;
     }
     if (array_key_exists($pk_name, $db_fields) && $db_fields[$pk_name] != '') {
         //update
         $sql = "UPDATE `{$table_name}` SET ";
         foreach ($db_fields as $field => $val) {
             if ($field == $pk_name || $val == '') {
                 continue;
             }
             $sql .= "`{$field}` = '" . mysql_real_escape_string($val) . "', ";
         }
         $sql = preg_replace('/, $/', '', $sql);
         //remove final comma
         $sql .= " WHERE `{$pk_name}` = '" . mysql_real_escape_string($db_fields[$pk_name]) . "'; ";
         if ($res = mysql_query($sql)) {
             return $db_fields[$pk_name];
         } else {
             //ERROR
             print "\nDID NOT UPDATE:\n{$sql}\n";
         }
     } else {
         $sql1 = "INSERT INTO `{$table_name}` (";
         $sql2 = "VALUES (";
         foreach ($db_fields as $field => $val) {
             if ($val == '') {
                 continue;
             }
             $sql1 .= "`{$field}`, ";
             $sql2 .= "'" . mysql_real_escape_string($val) . "', ";
         }
         $sql1 = preg_replace('/, $/', ')', $sql1);
         //remove final comma
         $sql2 = preg_replace('/, $/', ')', $sql2);
         //remove final comma
         $sql = $sql1 . $sql2 . ';';
         if ($res = mysql_query($sql)) {
             print "inserting";
             return DBQuery::get_last_id();
         } else {
             //ERROR
             print "\nDID NOT UPDATE:\n{$sql}\n";
         }
     }
 }