Short answer: NO.
The long answer is more complicated.
You must be sure to protect your SQL queries against injection bugs. The best way to do this is to never directly inject user data into your queries, but instead use the SQL placeholders of a database driver to do the insertion for you. This is the safest method by far. Your queries will end up looking like this:
INSERT INTO table_name (user_id, comment) VALUES (:user_id, :comment)
Data is then bound to the various placeholders in a way that the driver can encode it correctly. Being disciplined about this avoids nearly all SQL injection problems.
You must also protect your HTML from XSS attacks by not allowing users to insert arbitrary HTML with scripting into your pages. You should always render user input as the HTML entitized equivalent unless you're absolutely sure that this user content is free of <script>
type tags or JavaScript snuck into various elements. Note that this is very hard to do correctly since JavaScript is not confined to script tags at all. It can appear as attributes on an HTML element or even in CSS style definitions.
Further, you should never use mysql_query
or any related functions in a new application. These methods are dangerous by default and will cause you severe harm if you miss even one variable. Automated SQL injection tools have a terrifying list of features, and all that these tools require is one unescaped variable.
Thankfully mysql_query
is deprecated, it produces warnings in PHP 5.5.0, and will be removed entirely in future versions of PHP.
At the very least you should be using PDO for your database access. It supports named placeholders and makes it very easy to audit your database interface code to be sure it's safe. Mistakes will stand out. As a safety measure, it might be best to define your query strings with single quotes like 'INSERT INTO ...'
so that if you make the mistake of putting in a variable it won't be interpolated by accident but will end up yielding a harmless SQL error.
Ideally you should be using a PHP framework to build your applications. Most of these have standardized methods for safe database access, HTML escaping and XSS protection. It is not something you can do on your own unless you want to spend a year writing a framework of your own.