use mysql_real_escape_string() function to escape characters in all input fields. Not just to enable people to enter quotes but also to prevent evil people to enter harmfull code.
$title = mysql_real_escape_string($_POST['title']);
$content = mysql_real_escape_string($_POST['content']);
$creator = mysql_real_escape_string($_POST['creator']);
Mind you the connection to mysql has to be established in order to use this function. BTW: It is recommended to switch to mysqli extension.
broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13
You have to validate/sanitize input values whenever you either store them in a db or use them in javascript, HTML, CSS, email or any other possible context. If you forgot to do it you risk your app being compromited by SQL injection, XSS attack and similar. Sanitizing means basically escaping or replacing the characters that are unwanted in a particular context like:
- if you intend to store user entered data into database then most unwanted character is
' (single quote). If you forget to escape it the bad guy can enter code that will change your SQL statemnt in a way that you do not want. - if you intend to use user entered data in your html then for example you do not want characters
< and > and sometimes & get into html since they can be used to insert harmful client side script code into html - etc...
See nice articles here and here and google for sql injection, XSS, html injection...
broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13
And the same goes for cookie values. Sanitize them before you use them.
broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13
Question Answered as of 6 Months Ago by
broj1
and
ddymacek