Warning / Error

I am trying to use the following php code to see is a user is active, for loggin in purposes but I get errors.

The code:

[php]<?php
function user_exists($username) {
$username = sanitize($username);
$query = "SELECT COUNT(user_id) FROM users WHERE username = $username";
return (mysqli_query($query, 0) == 1) ? true : false;
}
?>[/php]

When I run the login page I get this error:

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\xampp\htdocs######\users.php on line 5

Being new to mysql / mysqli I would be greatful for any help in solving this problem.

Thanks is advance.

Where is the link object?

[php]mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] )[/php]

Take a look at what you’re doing.

mysqli_query($query, 0)

You’re passing in the query for the Link object and an integer of 0 for the $query.

http://php.net/manual/en/mysqli.query.php

Sponsor our Newsletter | Privacy Policy | Terms of Service