0

the code below is display the else statement, but when $getlogin == 0 it is not displaying

while ($getlogin = mysql_fetch_array($checklogin)) {
        if ($getlogin == 0) {
            echo "NOTHING TO DISPLAY";
        }
        else{
            echo $getlogin['username'];
            echo $getlogin['password'];
        }
    }
tadman
  • 208,517
  • 23
  • 234
  • 262
Bit
  • 41
  • 4
  • It is correct ! show other code snippet and use mysqli_* function – Akshay Parate Apr 25 '18 at 02:40
  • A resultset row is not `0`. Please stop using `mysql_` functions. – mickmackusa Apr 25 '18 at 02:41
  • 1
    Please [don't use `mysql_*`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php?rq=1); the `mysql_*` functions are outdated, [deprecated](http://us3.php.net/manual/en/intro.mysql.php), and insecure - they have been removed entirely from modern versions of PHP (version 7.0 and higher). Use [`MySQLi`](http://us3.php.net/manual/en/book.mysqli.php) or [`PDO`](http://us3.php.net/manual/en/intro.pdo.php) instead. – elixenide Apr 25 '18 at 02:43
  • This code snippet has nothing wrong except you are using `mysql_` interface, which is almost dead. We cannot pinpoint the problem just by looking at this very little detailed snippet.. – Romeo Sierra Apr 25 '18 at 02:45
  • thank you guys, i will update my self in mysqli or PDO, but for now, it is not displaying the echo"NOTHING TO DISPLAY". – Bit Apr 25 '18 at 02:52
  • **WARNING**: Writing your own access control layer is not easy and there are many opportunities to get it severely wrong. Please, do not write your own authentication system when any modern [development framework](http://codegeekz.com/best-php-frameworks-for-developers/) like [Laravel](http://laravel.com/) comes with a robust [authentication system](https://laravel.com/docs/master/authentication) built-in. At the absolute least follow [recommended security best practices](http://www.phptherightway.com/#security) and **never store passwords as plain-text** or a weak hash like **SHA1 or MD5**. – tadman Apr 25 '18 at 03:01
  • @RomeoSierra That code snippet is so full of alarm bells it should be deafening. – tadman Apr 25 '18 at 03:02
  • @tadman Didn't get you... – Romeo Sierra Apr 25 '18 at 03:05
  • @RomeoSierra `$checklogin` undoubtedly contains untold security problems as this is a home-rolled login system. – tadman Apr 25 '18 at 03:07
  • @tadman You are being judgmental.. :D – Romeo Sierra Apr 25 '18 at 03:12
  • @RomeoSierra I've seen way too many questions here with apocalyptically bad security holes. Remember, it only takes *one* tiny slip and your site can be cracked wide open. – tadman Apr 25 '18 at 03:15
  • 1
    @tadman Yup.. I totally agree with you.. :) When I said *there's nothing wrong* I was referring to syntactical aspects. Semantically, there is a multitude of problems here.. – Romeo Sierra Apr 25 '18 at 03:17

1 Answers1

2
   $checklogin = mysql_query($queryContents);

    if(mysql_num_rows($checklogin)== 0){
       echo "NOTHING TO DISPLAY";
    }
    else{
       while($getlogin = mysql_fetch_array($checklogin)) {

         var_dump($getlogin);

       }
    }

you can use php empty function also to check empty like this

if (empty($checklogin)) {
       echo 'NOTHING TO DISPLAY';
}else{
    while($getlogin = mysql_fetch_array($checklogin)) {
       var_dump($getlogin);
     }
}
Kamalesh M. Talaviya
  • 1,422
  • 1
  • 12
  • 26