0

I want to save the JSON coordinates of polygon in the PostGIS database. This is my PHP code-

$coordinates  = ($_POST['Coordinates']);
$query   = "INSERT INTO table_name (column_name) VALUES
   (ST_SetSRID(ST_GeomFromGeoJSON ('{
                      ['".($coordinates) ."']
      }'), 4326))"
$success =  pg_query($conn,$query);

where Coordinates are-

{"type":"polygon","coordinates":[[[-97.53662109375,43.67581809328341],[-98.096923828125,42.60970621339408],[-96.427001953125,42.924251753870685],[-97.53662109375,43.67581809328341]]]}

but the error is- "Parse error: syntax error, unexpected '$success' (T_VARIABLE)" column_name is polygon type column in table.

please someone correct me how to resolve syntax error. Thanks.

Shivam Pande
  • 184
  • 2
  • 14

1 Answers1

0

T_VARIABLE error mainly occurs because of the syntax error. You missed a Semicolon before $success line. Please check the syntax

$coordinates  = ($_POST['Coordinates']);
$query   = "INSERT INTO table_name (column_name) VALUES
   (ST_SetSRID(ST_GeomFromGeoJSON ('{
                      ['".($coordinates) ."']
      }'), 4326))";
$success =  pg_query($conn,$query);
Shreyas Achar
  • 1,407
  • 5
  • 36
  • 63
  • i have already tried that but then the eror is- "Query failed: ERROR: syntax error at or near "{" LINE 3: ['{"type":"polygon","coordinates"" – Shivam Pande Jan 31 '18 at 12:15
  • Can you please `echo $query;` and show here – Shreyas Achar Jan 31 '18 at 12:20
  • INSERT INTO polygon (coordinates) VALUES (ST_SetSRID(ST_GeomFromGeoJSON ('{ ['{"type":"polygon","coordinates":[[[-95.811767578125,41.20345619205131],[-94.46044921875,40.371658891506094],[-95.943603515625,40.34654412118006],[-95.811767578125,41.20345619205131]]]}'] }'), 4326)) – Shivam Pande Jan 31 '18 at 12:25