问题描述
我创建了一个评论表单,它会将评论插入数据库
并立即显示。我想确保用户将不需要的数据插入数据库或执行查询是安全的。
这是我的PHP代码,这是做对了吗?还有什么我应该为了让它更安全吗?
$ handle = mysql_connect($ host,$ user,$ password)或die( 对不起,看起来好像
就像发生错误一样。');
$ sql =" INSERT INTO评论(id,comment,name,quotekey) )VALUES(NULL,
''$ comment'',''name'',''$ key'')" ;;
mysql_real_escape_string ($ sql);
mysql_select_db($ database);
mysql_query($ sql);
mysql_close ($ handle);
谢谢,
Zach Wingo
I created a comment form which will inserts the comments into a database
and displays them immediately. I want to make sure that its safe from
users inserting unwanted data into the database or executing queries.
Here''s my php code, is this done right? Is there anything else I should
to to make it more secure?
$handle = mysql_connect($host,$user,$password) or die (''Sorry, looks
like an error occurred.'');
$sql = "INSERT INTO comments (id, comment, name, quotekey) VALUES (NULL,
''$comment'', ''$name'', ''$key'')";
mysql_real_escape_string($sql);
mysql_select_db($database);
mysql_query($sql);
mysql_close($handle);
Thanks,
Zach Wingo
推荐答案
这篇关于mysql_real_escape_string()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!