3

I am confused about why I am received the following message:

mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given

This question is different from previous queries because my query actually executes correctly (values were indeed entered into the database). So, I would expect MySQL to return a result set and NOT A BOOLIAN.

Below is my function:

function join_main_newsletter($firstName = null, $email)
{
    global $dbc;
    $valuesEntered = "values entered";

    $insert = "INSERT INTO newsletter (first_name, email ) VALUES ('name', 'testemail@yahoo.com')";

    $R3 = mysqli_query($dbc, $insert) or trigger_error("Query Failed! SQL: $sql - Error: " . mysqli_error(db_conx), E_USER_ERROR);
    if (mysqli_num_rows($R3) == 1) {
        return $valueentered;
    } else {
    }
}

And here is part of the results from the error:

[valuesEntered] => values entered
    [insert] => INSERT INTO newsletter (first_name, email ) 
                  VALUES ('name', 'testemail@yahoo.com')
    [R3] => 1
Dharman
  • 30,962
  • 25
  • 85
  • 135
andreea115
  • 53
  • 6
  • 1
    this is different. my query is working; i.e values are entering into the database. so, i don't have a fault in my query – andreea115 Oct 29 '13 at 13:58

2 Answers2

4

The mysqli_num_rows() function returns the number of rows in a result set. For insert, update and delete use mysqli_affected_rows

Dharman
  • 30,962
  • 25
  • 85
  • 135
Mihai
  • 26,325
  • 7
  • 66
  • 81
1

Use mysqli_affected_rows() - Number of rows affected by the last INSERT, UPDATE, REPLACE or DELETE query.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Krish R
  • 22,583
  • 7
  • 50
  • 59