How do I handle single quotes inside a SQL query in PHP?

前端 未结 3 1218
陌清茗
陌清茗 2020-12-12 08:10

I am using a particular query for inserting records. It is going well. I am even fetching records with a select query. But my problem is that, if the record contains single

相关标签:
3条回答
  • 2020-12-12 08:49

    You have to escape the data

    $sid = mysql_real_escape_string($sid);
    
    0 讨论(0)
  • 2020-12-12 08:55

    use http://www.php.net/manual/en/function.mysql-real-escape-string.php function on your string to quote "'" and other special symbols Other way to prevent injection - use different connections (login-passwords) with different rights for inserting and selecting. In this case mysql_real_escape_string wi9ll work good

    0 讨论(0)
  • 2020-12-12 08:56

    Your problem is much worse than this -- what if someone enters the value '; DROP TABLE poet; --? You need to use either mysql_real_escape_string() to escape the value, or use parametrized queries (with PDO, for example).

    It's 2011, for crying out loud. Why is SQL injection still a widespread problem?

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