Using PHP form to insert geometry from WKT and SRID into SQL Server 2017 I have a PHP 7.3 form that asks the user for a Name, a WKT and an SRID.  I would like to upload the WKT and SRID to SQL Server 2017 so that it creates a geometric object in Upload_WKT_Test using STGeomFromText:

&lt;?php
    if ($_SERVER['REQUEST_METHOD']=="POST") {
        $wkt = $_POST['wkt'];
        $srid = $_POST['srid'];
        $name = $_POST['name'];
        try {
            $wktQuoted = $pdo-&gt;quote ($wkt);
            //$wktQuoted = "'$wkt'";
            $sql = "INSERT INTO Upload_WKT_Test (Name, GeomCol1) VALUES (:name, :wktGeom)";
            $wktGeom1 = "geometry::STGeomFromText(";
            $wktGeom = $wktGeom1."".$wktQuoted.", ".$srid.")";
            //echo $wktGeom."&lt;br&gt;&lt;br&gt;".$name."&lt;br&gt;&lt;br&gt;";
            $stmnt = $pdo-&gt;prepare($sql);
            $theData = [':name'=&gt;$name, ':wktGeom'=&gt;$wktGeom];
            $stmnt-&gt;execute($theData);
        } catch(PDOException $e) {
            echo "Error: ".$e-&gt;getMessage();
        }
    } else {
        $wkt="";
        $alignment="";
        $srid="";
    }
?&gt;


My init.php:

&lt;?php
    ob_start();
    session_start();
     try {
        $pdo = new PDO( "sqlsrv:Server=localhost\SQLEXPRESS;Database=devdb", "", "");
        $pdo-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
        $pdo-&gt;setAttribute( PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC );
        //$pdo-&gt;setAttribute( PDO::ATTR_EMULATE_PREPARES, true );
    }

    catch( PDOException $e ) {  
        //die( "Error connecting to SQL Server" );
        //die(print_r($stmnt-&gt;errorInfo(), true));
        echo "Error: ".$e-&gt;getMessage();
    }  
    $root_directory = "testwkt";
    $from_email = "admin@somewhere.com";
    $reply_email = "admin@somewhere.com";
    include "php_functions.php";
?&gt;


I understand that the preferred method to accept user input via forms is to use a parameterized query to prevent SQL injection.  I believe the source of the error message has to do with the quotes around the WKT are not making it into the INSERT INTO statement.  Is it possible to surround text values from an input form with quotes (WKT) and use it to build a geometry object?

Example WKT entered into form POINT(100 10)

Example SRID 0

Example Name Test

Geometry from WKT (quotes are required):

geometry::STPointFromText('POINT (100 10)', 0)


Resulting error message:

SQLSTATE[42000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]
A .NET Framework error occurred during execution of user-defined routine or
aggregate "geometry": System.FormatException: 24114: The label
geometry::STGeomFrom in the input well-known text (WKT) is not valid. 
Valid labels are POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING,
MULTIPOLYGON, GEOMETRYCOLLECTION, CIRCULARSTRING, COMPOUNDCURVE, 
CURVEPOLYGON and FULLGLOBE (geography Data Type only). 
System.FormatException: at
Microsoft.SqlServer.Types.OpenGisTypes.ParseLabel(String input) at
Microsoft.SqlServer.Types.WellKnownTextReader.ParseTaggedText(OpenGisType type) at 
Microsoft.SqlServer.Types.WellKnownTextReader.Read(OpenGisType type, Int32 srid) at 
Microsoft.SqlServer.Types.SqlGeometry.GeometryFromText(OpenGisType type, SqlChars text, Int32 srid) at
Microsoft.SqlServer.Types.SqlGeometry.Parse(SqlString s) .


Upload_WKT_Test table:

CREATE TABLE dbo.Upload_WKT_Test
    ( id int IDENTITY (1,1),
    Name varchar(50),
    GeomCol1 geometry );
GO


WKT - Well Known Text - a way to represent a geometric object (point, line, polygon for example) in text format.  More info here.

SRID - Spatial Reference System Identifier - an integer that represents a coordinate system.  More info here.

More info about working with Geometry Instances in SQL Server and Azure SQL Database can be found here.

More info about STGeomFromText
The answer was provided by Zhorov in Stack Overflow here

Reposting the answer here in the hopes it will benefit someone:

You should include geometry::STGeomFromText in your T-SQL statement and bind the value for $wkt parameter without using PDO::quote:

&lt;?php
    if ($_SERVER['REQUEST_METHOD']=="POST") {
        $wkt = $_POST['wkt'];
        $srid = $_POST['srid'];
        $name = $_POST['name'];
        try {
            $sql = "
               INSERT INTO Upload_WKT_Test (Name, GeomCol1) 
               VALUES (:name, geometry::STGeomFromText(:wkt, :srid))";
            $stmnt = $pdo-&gt;prepare($sql);
            $theData = [':name'=&gt;$name, ':wkt'=&gt;$wkt, ':srid'=&gt;$srid];
            $stmnt-&gt;execute($theData);
        } catch(PDOException $e) {
            echo "Error: ".$e-&gt;getMessage();
        }
    } else {
        $wkt="";
        $alignment="";
        $srid="";
    }
?&gt;