You should not use plain mysql_query
To quote php.net
Warning This extension is deprecated as of PHP 5.5.0, and will be
removed in the future. Instead, the MySQLi or PDO_MySQL extension
should be used. See also MySQL: choosing an API guide and related FAQ
for more information. Alternatives to this function include:
mysqli_query() PDO::query()
Try using PDO or mysqli.
This is essential to prevent mysql injections.
http://php.net/manual/en/pdo.prepared-statements.php
Here is an example for how to do this with PDO
$config['db'] = array(
'host' => 'localhost',
'username' => 'username',
'password' => 'password',
'dbname' => 'dbname'
);
$db = new PDO("mysql:host={$config['db']['host']};dbname={$config['db']['dbname']}",
$config['db']['username'], $config['db']['password']);
$sql = "SELECT * FROM `users`";
$stmt = $db->prepare($sql);
$stmt->execute();
$users = $stmt->fetchAll()
$username = 'Bob';
$email = 'bob@gmail.com';
$nickname = 'BobTheMan';
foreach($users as $user)
{
if($user['username'] == $username)
{
// there is a user by this username
}
if($user['email'] == $email)
{
// there is a user by this email
}
if($user['nickname'] == $nickname)
{
// there is a user by this nickname
}
}