-2

i am new in PHP world. anyhow i am trying to make logging form which authenticate the entered data from a database (that data will be entered from sing-up form which is working fine) but its given me the following error.

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in \wamp\www\hightech\login_form.php on line 23

and my code is:

HTML form: index.php

<form id="login" action="login_form.php" method="post">
   <table style="color:white;border-color:white">
            <tr>
                 <td align="center" width="300" colspan="2">
                     <h3>Log In</h3>
                 </td>
            </tr>
            <tr>
                 <td align="right" width="200" id="username">
                      User&nbspName
                 </td>
                 <td>
                    <input type="text" name="user_name" placeholder=" Type user name" style="width:170;color:blue;text-align:center;border-top-left-radius:25;border-bottom-right-radius:25;"/>
                 </td>

            </tr>
            <tr>
                 <td align="right" id="passd">
                     Password
                 </td>
                 <td>
                     <input type="password" name="pass" placeholder="Type  password" style="width:170;color:blue;text-align:center;border-top-left-radius:25;border-bottom-right-radius:25;"/>
                 </td>
            </tr>
            <tr>
                 <td width="300" colspan="2" align="right">
                     <input type="submit" value="Log In" onclick="chack_info()" style="color:blue;border-top-left-radius:25;border-bottom-right-radius:25"/>
                 </td>
             </tr>
       </table>
    </form>

loging_form.php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "hightech"; 
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

   $user_name= filter_input(INPUT_POST, 'user_name');
   $password=  filter_input(INPUT_POST, 'pass');
   $result=mysql_query("SELECT * FROM accounts WHERE  user_name='$user_name' and password='$password'");

   $count=mysql_num_rows($result);
   if($count==0){
      echo'data found';
   } else {
      echo 'Wrong Username or Password!'; 
   }

Plz help me as soon as possible.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Hacan Champ
  • 53
  • 11

1 Answers1

1

Use this:

$result=mysqli_query($conn, "SELECT * FROM accounts WHERE  user_name='$user_name' and password='$password'");

$count=$result->num_rows;
if($count==0){
   echo'data found';
} else {
   echo 'Wrong Username or Password!'; 
}

You cannot mix MySQLi and MySQL because these are two different database drivers which other architecture (OOP vs. Non-OOP).

Richard
  • 2,840
  • 3
  • 25
  • 37