PHP 保护查询免受 mysql 注入。
如何将 mysql_real_escape_string() 添加到此:::
$result = mysql_send("INSERT customers SET user='$username', pword='$pass1',
firstname='$firstname', lastname='$lastname', email='$email',
active='No', activecode='$activecode', dateofbirth='$dateofbirth',
gender='$gender', title='$title', occupation='$occupation',
address='$address', city='$city', country='$country', zip='$zip',
mobile='$mobile', telephone='$telephone', fax='$fax',
website='$website'
");
How can I add mysql_real_escape_string() to this:::
$result = mysql_send("INSERT customers SET user='$username', pword='$pass1',
firstname='$firstname', lastname='$lastname', email='$email',
active='No', activecode='$activecode', dateofbirth='$dateofbirth',
gender='$gender', title='$title', occupation='$occupation',
address='$address', city='$city', country='$country', zip='$zip',
mobile='$mobile', telephone='$telephone', fax='$fax',
website='$website'
");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我这样做(假设 HTML 表单的字段名称与数据库字段名称完全匹配):
对我来说看起来很整洁。
I make it this way (assuming HTML form's field names exactly match a database field name):
looks neat to me.
也许你可以花一些时间看看 Doctrine ORM。
保存到数据库将如下所示:
一切都将被转义,您的程序也将更具可读性......
Maybe you can take some time and check out Doctrine ORM.
Saving to database would then look like:
Everything will be escaped, your program will also be more readable ...
逃跑是相当老套的事情。相反,使用准备好的语句来分隔查询和数据。
这可以为您节省很多的麻烦。
根据获取数据的位置,您也可以直接将其放入数组中。
例如,如果您从表单中获取大量数据,变量名称为 pword、user 等,您可以直接使用该数组
Escaping is quite old-school. Instead, use prepared statements to separate queries and data.
This saves you lots of headaches.
Depending on where you get the data from, you might also directly have it in an array.
For example, in case you get a lot of data from a form, with the variable names pword, user and so on you can directly use that array