I am trying to write an POLYGON into an column named SHAPE which is a geometry type. And created query which looks
$sql = "INSERT INTO rokka(zone,district,location,area,SHAPE)
VALUES ('$zone','$district','$location','$area',PolygonFromText('$polywrite'))";
The variable $polywrite
comes as
var polygon = 'Polygon((' + northeastlngLat[0] + ' ' + northeastlngLat[1] + ',' + northwestlngLat[0] + ' ' + northwestlngLat[1] + ',' + southwestlngLat[0] + ' ' + southwestlngLat[1] + ',' + southeastlngLat[0] + ' ' + southeastlngLat[1] + ',' + northeastlngLat[0] + ' ' + northeastlngLat[1] + '))';
$polywrite = "<script>document.write(polygon)</script>";
The arrays contain the coordinates. And when executing
if ($connect->query($sql) === TRUE) {
session_start();
header('location: admin.html');
session_destroy();
} else {
echo "Error: " . $sql . "<br>" . $connect->error;
}
The error it shows is
Column 'SHAPE' cannot be nullError: INSERT INTO rokka(zone, district,location,area,SHAPE) VALUES ('Rapti', 'Rolpa','Liwang','603750', PolygonFromText('Polygon((85.06290725100276 28.00935569163021,85.06392404943365 28.0093478254886,85.06393735099435 28.01070145242192,85.06292053985693 28.010709319009717,85.06290725100276 28.00935569163021))'))
Column 'SHAPE' cannot be null
But whenever I run the query
INSERT INTO rokka(zone, district,location,area,SHAPE)
VALUES ('Rapti', 'Rolpa','Liwang','603750', PolygonFromText('Polygon((85.06290725100276 28.00935569163021,85.06392404943365 28.0093478254886,85.06393735099435 28.01070145242192,85.06292053985693 28.010709319009717,85.06290725100276 28.00935569163021))'))
in my database directly It works exactly as it should. All the values are written into the respective columns. Please help me figure out what i am doing wrong.
$polywrite = "<script>document.write(polygon)</script>";
It looks like, you generate a part of html document and writes polygon via javascript. Why not to usepolygon
directly in$sql = ...
?INSERT
statement in the error message do not match the columns in the statement you said you assigned to$sql
. Is it being changed somewhere?polygon
the coordinates are to be transfromed that i do using proj4js (javascript library), hence need to get the value from javascript part of page.