How to escape quotes when inserting into database with PHP

前端 未结 4 616
闹比i
闹比i 2021-01-12 07:22

I\'m quite new to PHP so sorry if sounds such an easy problem... :)

I\'m having an error message when inserting content which contains quotes into my db. here\'s wha

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-12 07:26

    Your code

    $sql="INSERT INTO articles (title, body, date) VALUES ('$title','$body','$nowdate'),";
    

    should be as follows

    $sql="INSERT INTO articles (title, body, date) VALUES ('$title','$body','$nowdate')";
    

    comma should not be there at the end of query

提交回复
热议问题