What are common errors when using GeomFormText in PHP for MySQL queries?

Common errors when using GeomFromText in PHP for MySQL queries include not properly formatting the WKT (Well-Known Text) geometry string, not enclosing the WKT in single quotes, and not escaping special characters. To solve this issue, make sure to properly format the WKT string, enclose it in single quotes, and use mysqli_real_escape_string to escape special characters.

// Example of using GeomFromText in PHP for MySQL queries
$wkt = "POINT(10 20)";
$escaped_wkt = mysqli_real_escape_string($connection, $wkt);

$query = "INSERT INTO locations (geom) VALUES (GeomFromText('$escaped_wkt'))";
$result = mysqli_query($connection, $query);

if($result) {
    echo "Geometry inserted successfully.";
} else {
    echo "Error inserting geometry: " . mysqli_error($connection);
}