If you use your code just like this then it's vulnerable for SQL Injection. I would strongly recommend using mysql_real_escape_string as you insert data into your database to prevent SQL injections, as a quick solution or better use PDO or MySQLi.
If you are going to use mysql_*
then I'd recommend reading the PHP manual chapter on the mysql_*
functions,
where they point out, that this extension is not recommended for writing new code. Instead, they say, you should use either the MySQLi or PDO_MySQL extension.
I also checked mysql_connect
and found a weird regularity which is - if you use "
on mysql_connect
arguments, then it fails to connect and in my case, when I was testing it, it happened just described way, so, please try this instead:
$con = mysql_connect('localhost','username','password');
Replace "
to '
as it's shown in the PHP Manual examples and it might work!
EDITED
For those who downvote - TRY first! I tested it on my server with "
and it gave me an error: Warning: mysql_connect(): Access denied for user
. I use PHP version 5.4.6!
Login to your server with SSH and run php --modules
- if you don't see mysql
in the list - then it's the reason of your fatal error.