Warning: mysql_num_rows() expects parameter 1 to be resource, object given [duplicate]

Asked
Active3 hr before
Viewed126 times

5 Answers

objectwarning
90%

mysql_num_rows() expects parameter 1 to be resource, object given in C:\wamp\www\android_connect\authenticate_user.php on line 35, i think mysqli use mysqli_num_rows not mysql_num_rows function i.e your connection established with mysqli so expects parameter 1 to be resource is only for mysqli_num_rows.. – ankit verma Jul 3 '14 at 8:51 , Meta Stack Overflow ,Stack Overflow en español

change this

  if (mysql_num_rows($result) > 0)
load more v
88%

Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.

<pre>if(isset($_POST['submit'])){
    

$first_name = test_input($_POST["firstname"]);
$last_name = test_input($_POST["lastname"]);
$id = test_input($_POST["member_id"]);
$username = test_input($_POST["username"]);
$password = test_input($_POST["password"]);
$email = test_input($_POST["email"]);
$membertype = test_input($_POST["membertype"]);
$phone = test_input($_POST["phonenumber"]);
$department = test_input($_POST["department"]);

 
  $query = "SELECT * FROM lms WHERE  ID='".$id."' OR email='".$email."' OR  user_name='".$username."' ";
$resultdata = mysqli_query($link , $query);
$data = mysqli_fetch_array($resultdata, MYSQLI_NUM);
    
if($data[0] > 1) {
    echo "User Already in Exists<br/>";
}

else
{
    $sql = "INSERT INTO `member` (`ID`, `first_name`, `last_name`, `member_type`, `password`, `email`, `phoneNo`, `department`, `user_name`)
VALUES ('$id', '$first_name', '$last_name','$membertype','$password','$email','$phone','$department','$username')";
    if (mysqli_query($link,$sql))
    {
        echo "You are now registered<br/>";
    }
    else
    {
 echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);    }
}
    
    
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}

?>
$results = mysql_num_rows($resultdata);
$user = mysqli_fetch_assoc($resultdata);
load more v
72%

I keep on receiving an error message using mysql_num_rows(), can you help me figure out what went wrong on my code?,When there is an error, mysql_query() returnse false instead of a resource object. Check the return value of mysql_query() before you pass it to mysql_num_rows().,For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.,Probably mysql_query() failed. In this case it returns false. Use mysql_error() to find out, what happens.

Here's my code:

<?php 
//check if the user press submit
if (isset($_POST['submit'] )) {

    $customer = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["username"]); // filter everything but numbers and letters
    $password = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["password"]); // filter everything but numbers and letters

    $sql = mysql_query("SELECT id FROM members WHERE username='$customer' AND password='$password' LIMIT 1"); // query the person
    // ------- MAKE SURE PERSON EXISTS IN DATABASE ---------
    $existCount = mysql_num_rows($sql); // count the row nums
    if ($existCount == 1) { // evaluate the count
         while($row = mysql_fetch_array($sql)){ 
             $id = $row["id"];
         }
         $_SESSION["id"] = $id;
         $_SESSION["customer"] = $customer;
         $_SESSION["password"] = $password;
         header("location: index.php");
         exit();
    } else {
        echo 'That information is incorrect, try again <a href="customer_login.php">Click Here</a>';
        exit();
    }
}
?>

and when I search for that error it says that

1146: Table 'kossu.nonexistenttable'
doesn 't exist
load more v
65%

I want to check if a user has already been registered in the database to not have duplicate users, but when I use mysqli_num_rows to know if there is any line with that user the error of the title. , You're mixing mysql with mysqli and procedural mode with object-oriented mode, which is wrong. Try to do everything in one way: , On the insert, if the id is a primary key it is not possible to make an null insert. Ideally the id would be Auto_increment and be primary key, so you do not need to give input. , mysql is obsolete in newer versions of php, so use mysqli

You're mixing mysql with mysqli and procedural mode with object-oriented mode, which is wrong. Try to do everything in one way:

$check = "SELECT * FROM user WHERE name='$user'";
$sql = $mysqli - > query($check);
$ln = $sql - > num_rows;
load more v
75%

When passed an UPDATE query, mysql_query() returns boolean TRUE for success and FALSE for failure, while mysql_num_rows() only accepts a resultset resource as its argument. In order to determine how many rows the UPDATE query affected, call mysql_affected_rows() with the connection resource as its argument.,you can't print the result from mysqli_query, it is mysqli_resource and for dumping the error you need to change mysql_error() to mysqli_error() ,yo need create the user "pma" in mysql or change this lines(user and password for mysql):,You cannot interchangeably use mysql and mysqli functions, for example:

I'm new in using PHP. I made something simple to connect to MySQL and select a database:

$conn = mysqli_connect($db_host, $db_admin, $db_pass) or die(mysql_error());
// these variables are previously declared and initialized 

$selected_db = mysql_select_db($db_name, $conn) or die(mysql_error());

When I tested it, I got a successfully-established connection and the following warning:

mysql_select_db() expects parameter 2 to be resource, object given
load more v

Other "object-warning" queries related to "Warning: mysql_num_rows() expects parameter 1 to be resource, object given [duplicate]"