Hello I am new to PHP and this is my code and i am getting error as given bellow please help me

<?php

$myhost = "localhost";
$db_username = "root";
$db_password = "";
$db_Name = "login_db";
$table="login";

$con = mysqli_connect($myhost,$db_username,$db_password) or die ("Connection Failed");

mysqli_select_db ($con, $db_Name) or die ("Cannot Find the Data Base");

$username = $_POST['uname'];
$password = $_POST['password'];

//$conn = mysqli_connect($myhost,$db_username,$db_password,$db_Name);
//$sql ="select * from '$table' where username='$username' AND password = '$password'";

$results = mysqli_query($con,"select * from '$table' where username='$username' AND password = '$password'");

$count = mysqli_num_rows($results);


echo $count;
echo $username . "<br/>";
echo $password . "<br/>";



?>


<html>

<head>
    <title> Login Control </title>
</head>

<body>
    <br/><br>

<!-- <form name= "myloginForm" action="" method="POST">
Username: <input id="fname" name="fname" type="text">
Password:<input id="password" name="password" type="password">
Email ID:<input id="email" name="email" type="email">
<input type="submit" value="Please Register">
</form> -->
   
</body> </html>

Error: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\PHP\Login\check_login.php on line 21

[Mod: Added [code]...[/code] tags].

    Read the manual: mysqli_query

    Return Values

    Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.

    MySQLi has functions to report why the query failed. Use those. And in future check that the query succeeded before using its results (kind of like you do for the earlier function calls, though just dying is a pretty brutish way of doing it).

    Oh, and never put user-supplied data directly into a database query.

      Write a Reply...