php - Why am I getting a "Query was empty" error from this block of code? -


i'm trying make login/register system , when press login should exists...

<?php include 'core/init.php';   function user_exists($username){ $username = sanitize($uusername); $query = mysql_query("select count (`user_id`) `users` `username` = '$username'");  $result = mysql_query($query) or die(mysql_error());  // check if query successful $row = mysql_fetch_array($result); // fetch first row return ($row[0] > 1);  // if there 1 or more users name, return true.     } 

here code should make page "exists":

<?php include 'core/init.php';  if(user_exists('zuzima') === true) { echo 'exists'; } die();  if (empty($_post) === false) { $username = $_post['username']; $password = $_post['password'];  if(empty($username) === true || empty($password) === true){     $errors[] = 'you need username , password.'; } else if (user_exists($username) === false) {     $errors[] = 'we can\'t find username. have registered?'; } } ?> 

please me i've been working on 6 months @ least.

the $query getting assigned resource handle mysql_query, passing resource handle in string mysql_query

$query = mysql_query("select count (`user_id`) `users` `username` = '$username'");  $result = mysql_query($query) or die(mysql_error()); 

should

$result = mysql_query("select count(`user_id`) `users` `username` = '$username'") or die(mysql_error()) 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -