Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Junior Member
    Join Date
    Aug 2016
    Posts
    1
    Member #
    54979

    Problem with mysql_query(): and mysql_num_rows()

    Please help, whenever i try to log in ,it displays the following with user not found or wrong username
    Code:
    Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp\www\index.php on line 76
    
    Call Stack
    #	Time	Memory	Function	           Location
    1	0.0050	142112	{main}( )	..\index.php:0
    2	0.0160	150640	mysql_query ( )	..\index.php:76
    
    
    ( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\index.php on line 77
    
    Call Stack
    #	Time	Memory	Function	Location
    1	0.0050	142112	{main}( )	..\index.php:0
    2	0.0250	157504	mysql_num_rows ( )	..\index.php:77.
    Any help with this?..these are my source code.
    PHP Code:
    <?php
    session_start
    ();
    if(isset(
    $_SESSION['sesname']) && isset($_SESSION['sespass']) && isset($_SESSION['sestype']) && isset($_SESSION['sesfullname']) ){
        if(
    $_SESSION['sestype']=="registrar"){
            
    header('location:regestrar.php');
        }elseif(
    $_SESSION['sestype']=="accountant"){
            
    header('location:accountant.php');
        }else{
            
        }
    }else{
        
    }
    ?>

    <html>
    <head>
    <link rel="stylesheet" type="text/css" href="css/style_entry.css" />
    <link rel="stylesheet" type="text/css" href="css/style.css" media="screen"/>
    <link rel="stylesheet" type="text/css" href="css/style.css" media="screen"/
    <link rel="stylesheet" type="text/css" href="css/style_entry.css" />
    <link rel="stylesheet" type="text/css" href="css/structure.css"
    <link rel="stylesheet" type="text/css" href="css/menu.css" />
    <link rel="stylesheet" type="text/css" href="css/idcard.css" />
    </head>


    <body style="background-image:url(img/h.jpg);"> 
    <h4>&nbsp;</h4>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <div id="index">

    <div id="certbody" style="background-image: url(bgimage.png); background-repeat:no-repeat; background-position:70% 80%; ">
                <div class="head">
                <div class="sidea">
                <p><b>FEDERAL POLYTECHNIC ILARO</b></p>
                <p>KABALE CAMPUS P.O BOX 884, KABALE</p>
                <p style="color:red;"><b>IDENTITY CARD PROCESSING SYSTEM</b></p>
                <p><span style="color:red; float:left; padding-top:10px; font-style:italic; font-family:Bodoni MT Black;">00000</span><strong>ACADEMIC YEAR ...............</strong></p>
                </div>
                <div class="sideb"><img src="logo.png"  width="80%" height="90%" /></div>
                
                </div>
                <div class="bodymain">
                <div class="bodya">
                
               <label align="center"><font size="5" color="blue"></font></label>
        <form class="" method="POST" action="">

        <table>
        <tr><td>Username</td><td>
          <input type="text"  name="uname" placeholder="User Name" required name="username" pattern="[A-Za-z]{2,15}" title="Letters Only" maxlength="15" required autocomplete="off"></td></tr>
          
         <tr><td>Password</td><td>
         <input type="password"  name="pass" placeholder="Password" required name="password"></td></tr>
         
         <tr><td>
          <input type="submit" class="a" value="Login"  name="login" style="padding-top:2px;"></td><td>
          <input type="reset" class="a" value="Clear"  name="Clear" style="padding-top:2px;"></td></tr>
         
    </table>
                </div>
                <div class="bodyb"> 




    <?php

    if(isset($_POST['login'])){
        
    $username=$_POST['uname'];
        
    $password=$_POST['pass'];
        include
    "dbconn.php";
        
    $checklogin "SELECT * FROM users WHERE user_name='$username' &&    password='$password'";
        [
    B]$resultmysql_query($checklogin);[/B]
        [
    B]$count_resultmysql_num_rows($result);[/B]
        if(
    $count_result==1){
        
    $getdata=mysql_fetch_array($result);
        
    $type=$getdata['user_type'];
        
    $fullname=$getdata['first_name']." ".$getdata['last_name'];
        
    #create sessions
        
    $_SESSION['sesname']=$username;
        
    $_SESSION['sespass']=$password;
        
    $_SESSION['sestype']=$type;
        
    $_SESSION['sesfullname']=$fullname;
        if(
    $type=="registrar"){
            
    header('location:regestrar.php');
        }elseif(
    $type=="accountant"){
            
    header('location:accountant.php');
        }else{
            
    header('location:index.php');
        }
        
        
    #create sessions
            
        
    }else{
        echo
    '<span style="color:red;">User not found or  wrong password</span>';    
        }
        
        
    }else{
    }    

    ?>
    </html>

    </div>
    line 76 and 77 are the ones with bold letters.
    Thanks
    Last edited by Ronald Roe; Aug 18th, 2016 at 08:23 AM. Reason: CODE tags, bro.

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,686
    Member #
    5580
    Liked
    716 times
    Back in 2010, webhosts began warning people to switch to MySQLi (improved) or PDO (SQL prepare statements). This was because MySQL as it was known then would be obsolete by 2014. They extended that until 2015. Now, it is pretty much obsolete everywhere. You cannot use MySQL anymore.

    You need to either convert to MySQLi, or use PDO. PDO is the most accepted. It prepares all queries internally, thus protecting from SQL injections and other security issues.

    For now, you can convert to MySQLi. Use Google, search for: convert mysql to mysqli tutorial

    In your case, you are not a webhost, but are using WAMP. What you are getting is "warnings". Your scripts still work. You can suppress those warnings so you don't see them. Still, if you ever move your scripts to a shared webhost, they will not work. period.

    EDIT:
    Your other issues, like using SESSION with username and password is really a bad security situation. Using SESSION to determine login should not be either a password or username, but an encoded "key" that is compared with a key in the database ... on the row in the table that contains the user's information. The user's password in the database should also be encrypted so even you (the admin) will not know what it is. Basically, your script is very out-dated and susceptible to hacking.
    Last edited by mlseim; Aug 18th, 2016 at 05:25 AM.


  4. #3
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    mlseim is right, you need to move to mysqli.

    However, even in mysqli you'll likely get the same result. That is because the $result you're passing to mysql_num_rows doesn't have any actual results in it. Your query is returning nothing, so mysql_query is returning false, hence the "boolean given" part of the warning.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  5. #4
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,686
    Member #
    5580
    Liked
    716 times
    I didn't even look that far into the script ... MySQL was far enough for me to know there is a problem.

    So far, as much as I can determine, this is the best PDO tutorial I can find:
    https://phpdelusions.net/pdo



Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:02 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com