-1

I've file with this code but it shows error

    <?PHP
    //consider it connected to database already
    $name=$_POST['name'];
    $age=$_POST['age'];
    $sql="SELECT * FROM users WHERE name='$name' AND age='$age'";
    $query=mysql_query($sql);
    $num=mysql_num_rows($query);
    if($num==1){
    $_SESSION['name']="$name";
    $_SESSION['age']="$age";
    header("Location:thanks.php");
    }else{
    echo "none";
    }
    ?>

I'm getting error as follow

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\script\users.php on line 6

but i don't see any error so why this error shown! so any help

Funk Forty Niner
  • 74,372
  • 15
  • 66
  • 132

1 Answers1

0

First, you really should be using the mysqli api, as the mysql one is depreciated.

Secondly, mysql_query will either return a resource on success or a false on error. As the call to mysql_num_rows is throwing an error about not receiving a resource, it's safe to assume your query is throwing an error/failing for some reason.

You can use mysql_error to help you debug.

MasterOdin
  • 6,417
  • 1
  • 18
  • 33