Jump to content

INSERT query with values containing apostrephe


grantf

Recommended Posts

Hi, i have successfullly put together some code that writes form data to my mssql db however during testing, if the form field contains an apostrephe the query fails. how do you get around this?

 

this is the query line i am using..

 

$reason = $_POST['reason'];

 

$update = "INSERT INTO journals(reason) VALUES ('$reason')";

mssql_query($update, $link);

 

.. the form field might contain something like this, the cat's sat on the mat

 

this is the error..

 

PHP Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near 's'. (severity 15) in C:\Inetpub\wwwroot\forms\journal-send.php on line 71 PHP Warning: mssql_query() [function.mssql-query]: message: Unclosed quotation mark after the character string ');'. (severity 15) in C:\Inetpub\wwwroot\forms\journal-send.php on line 71 PHP Warning: mssql_query() [function.mssql-query]: Query failed in C:\Inetpub\wwwroot\forms\journal-send.php on line 71

Link to comment
Share on other sites

  • 2 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.