0

When I execute the following code, I gets this error:

Warning: mysql_num_rows() expects parameter 1 to be resource, object given in C:\wamp\www\my\myWork.php on line 53

Whats the wrong with this code?

<?php
if(isset($_POST['login']))
{
    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "Begin";

    $uName = $_POST["txtUsername"];
    $uPwd = $_POST["txtPwd"];

    echo "Your Username is: ".$uName."<br>";
    echo "Your password is: ".$uPwd."<br>";

    $conn = mysqli_connect($servername, $username, $password, $dbname);
    if(!$conn)
        die("Connection faild: " . mysqli_connect_error());

    $sql = "SELECT firstname from myguests WHERE firstname = '$uName'";
    $result = $conn->query($sql);

    if(mysql_num_rows($result) > 0)
        {
            echo "You have a login";
            $_SESSION['uname'] = $uName;
        }
    else
        echo "You don't have a login";
}
?>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Nishan256
  • 97
  • 7

1 Answers1

2

I believe that because you are using mysqli_connect that you need to use the mysqli_query($conn,$sql) notation.

Try this:

$result = mysqli_query($conn,$sql)
if(mysqli_num_rows($result) > 0)
stef
  • 14,172
  • 2
  • 48
  • 70