When the condition is false the statment insdie false condition is not showing.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • robin1983
    New Member
    • Oct 2007
    • 99

    When the condition is false the statment insdie false condition is not showing.

    Dear All,

    I have a simple login script, when the user put the correct information the loop is working but when they put wrong informtion the loop is not working. Kindly find the below code.

    The statement after if($result<0) is not working.
    Code:
    <?php
    include("dbConfig.php");
    if(isset($_POST['login'])){
        $userid = $_POST['userid'];
        $userpassword = $_POST['password'];
        $usertype = $_POST['usertype'];
    
        //$sql = mysql_query("SELECT * FROM logintable where UserID = '$userid'");
        //if($sql){
            $sql2 = mysql_query("SELECT * FROM logintable where UserID = '$userid' and UserPassword='$userpassword'");
            //echo "h2i";
            $result = mysql_num_rows($sql2) or die(mysql_error());
            if($result<0){
                echo "Sorry";
                exit;
            }
            else{
                while($row = mysql_fetch_array($sql2)){
                    $usertype1 = $row['UserType'];
                    $username =  $row['UserName'];
                    $userlastlogin = $row['UserLastLoginDateTime'];
                    $userlastip = $row['UserLastIP'];
    
                    echo $usertype1."-".$username."-".$userlastlogin."-".$userlastip;
                    SESSION_START();
                    $_SESSION['userid'] = $userid;
                    $_SESSION['username'] = $username;
                    echo $_SESSION['userid'];
                }								 
            }
        /*}
        else{
                echo "Sorry";
        }*/
    }
    ?>
    Last edited by Markus; Oct 31 '09, 11:56 AM. Reason: Please use [CODE] instead of [QUOTE]
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Well, your logic head is flawed. mysql_num_rows( ) will return the number of affected rows, if there are any. If there are 0 affected rows... yes, you guessed it, mysql_num_rows( ) will return 0.

    So, the problem is that you're checking for a number less than 0 (which you will never have). You want to be check if mysql_num_rows( ) is equal to 0.

    Mark.

    Comment

    • robin1983
      New Member
      • Oct 2007
      • 99

      #3
      thanks it working now

      Comment

      Working...