使用表单从JSON更改数据

时间:2018-11-29 11:05:03

标签: php json postgresql forms geojson

我正在尝试使用表单从数据库中选择数据并将其存储为geojson格式,但是当我尝试添加数据时,它说“ SyntaxError:JSON.parse:JSON第2行第1列出现意外字符”数据”,并且我希望每当有人在表单字段中输入其他值时更改数据。连接正常,当我不使用表单并从表格中输入一些值时,json文件有效。 这是代码:

表格:

<div style='background:#171E24; text-align:center'>
    <form class="form" method="post">
        <input type="text" name="number" id="number"  placeholder="number"  >
        <input type="text" name="startDate" id="sDate"  placeholder="start date"  >
        <input type="text" name="endDate" id="eDate" placeholder="end date">
        <input type="submit" name="search" id="search" value="search">
    </form>
    </div> 

PHP代码:

<?php
   if(isset$_POST['search']){
    include('testcon.php');
    $number='number';

    $startD=$_POST['startDate'];
    $endD=$_POST['endDate'];

    $startData=strtotime($startD.'00:00:00');
    $pgsqlstartdata=date('Y-m-d H:i:s',$startData);

    $endData=strtotime($endD.'23:59:59');
    $pgsqlenddata=date('Y-m-d H:i:s',$endData);

    $query=pg_query($connect,"SELECT number, condition, date, lat, long "
        . "FROM schema.table "
        . "WHERE number = '$number' AND "
        . "data BETWEEN '$pgsqlstartdata' and ' $pgsqlenddata' ");



          $geojson = array(
          'type'      => 'FeatureCollection',
          'features'  => array()
           );
           # Loop through rows to build feature arrays
           while($row = pg_fetch_array($query)) {
          $feature = array(

         'type' => 'Feature', 
         'geometry' => array(
          'type' => 'Point',
        # Pass Longitude and Latitude Columns here
        'coordinates' => array($row['lat'], $row['long'])
    ),
         # Pass other attribute columns here
          'properties' => array(
          'number' => $row['number'],
        'condition' => $row['condition'],

        )
    );
       # Add feature arrays to feature collection array
          array_push($geojson['features'], $feature);

      header('Content-type: application/json');
      echo json_encode($geojson, JSON_NUMERIC_CHECK);
      $conn = NULL;
      ?>
     }

`

我想将数据放在传单地图上,但我真的不明白如何从geojson文件中更改数据。

0 个答案:

没有答案