0

So, here's the query (copied and pasted from browser, echoed directly from the php code.)

INSERT INTO Azioni_report (Chiusa, Data, Descrizione, ID_report, IntEst, Tipo, Responsabile) 
VALUES (0, CONVERT(date, '2-12-2014', 105), 'verifica dell''efficacia', 1049, 1, 2, 12)

If I run it from my "test page", it works fine. When I run the exact same query in the page where I need it, it gives this error:

Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 102 [code] => 102 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near 'efficacia'. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near 'efficacia'. ) ) 1

I'm using SQL server.

Andrea
  • 162
  • 8

1 Answers1

1

There is a problem where you are not escaping your quotes properly. Escaping is done by prepending them with a backslash \ like so:

INSERT INTO Azioni_report 
    (Chiusa, Data, Descrizione, ID_report, IntEst, Tipo, Responsabile) 
VALUES
    (0, CONVERT(date, '2-12-2014', 105), 'verifica dell\'\'efficacia', 1049, 1, 2, 12);

To avoid this altogether, try reading up on PDO or mysqli and the parameterizing (or binding) of your queries in PHP:

PDO - PDO::prepare

mysqli - Prepared Statements

Community
  • 1
  • 1
RichardBernards
  • 3,146
  • 1
  • 22
  • 30