How to correctly sanitize mssql query that stores emails

后端 未结 1 1718
温柔的废话
温柔的废话 2021-01-24 17:59

I have a query that goes to a mailbox and tries to save all emails in a table. It works in most cases but it fails when the email content value has double or single quote marks.

1条回答
  •  有刺的猬
    2021-01-24 18:38

    You want to be using parameters:

    $query = "INSERT INTO test (email, body) VALUES (?,?);";
    $arrParams[]="my@domain.com";
    $arrParams[]="My email body has quotes\'s or double quotes \" in it.";
    $resource=sqlsrv_query($conn, $query, $arrParams); 
    

    Source: sqlsrv_query

    0 讨论(0)
提交回复
热议问题