insert text to sqlite where text have "

前端 未结 1 765
自闭症患者
自闭症患者 2021-01-23 04:07

I want to read query string from URL and save them into a sqlite database I face with these Error message:

PHP Warning:  SQLite3::exec(): near ",&qu         


        
1条回答
  •  执念已碎
    2021-01-23 04:29

    As mentioned by @HassanAhmed, this is what happens when inputs are not properly handled; you're seeing the same issue as if someone was using SQL injection against you. The quick fix is to wrap the fields in quotation marks:

    VALUES ("Ehsan", "$Tel", date('now'), "$Content");
    

    What you should be doing is binding the parameters:

    $sql =<<prepare($sql);
    $stmt->bindValue(':tel', $_REQUEST['from']);
    $stmt->bindValue(':content', $_REQUEST['text']);
    
    $ret = $stmt->execute();
    

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