mysql - my php code don't work result -


i have issue in php script when enter correct username echo "user found" , when

i enter wrong user name echo "user found".

here code please check , let me know, if !$result variable supposed work didn't. why?.

<?php     echo "enter username \n";     $username = trim(fgets(stdin));     echo "enter password\n";     $password = trim(fgets(stdin));      //connecting database     $db = mysql_connect("localhost","sqldata","sqldata") or die(mysql_error());      //selecting our database     $db_select = mysql_select_db("accounts", $db) or die(mysql_error());      $result= mysql_query("select * login username = '$username' ");     if (!$result)     {         echo "error no user";     }     else     {         echo "user found";     }      mysql_close($db) ?> 

mysql_query returns result resource, unless there's actual error in mysql query. result gives absolutely no indication whether there rows in it.

try this:

$result = mysql_fetch_assoc(mysql_query("select * `login` `username`='".mysql_real_escape_string($username)."'")); if( !$result) echo "error no user"; else echo "user found"; 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -