sql server - Issue escaping single quote on mssql 2008 from php codeigniter -


i doing insert database 1 of columns trying escape single quotes user might type. example, it's, using codeigniter framework , did following escape column:

$test=$this->db->escape($test); 

but sql-server error when submit. example if type it's, trying this

insert table (test) values(''it''s'') 

when should be

insert table (test) values('it''s') 

why inserting single quotes?

you escaping entire sql statement when should escaping string inserting. example, lets have following code currently.

$test = "insert table (test) values ('" . $value . "');"; 

you should change be

$test = "insert table (test) values ('" . $this->db->escape($value) . "');"; 

edit

as liam pointed out, since using codeigniter, may want consider using query binding provide. see url more information: https://ellislab.com/codeigniter/user-guide/database/queries.html


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -