Viewed   119 times

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

 Answers

3

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

Friday, September 2, 2022
 
1

You've mixed procedural and object-oriented MySQLi styles. This has led to you trying to use the functions like mysqli_query($mysqli) instead of the member functions like $mysqli->query(). Your $mysqli is an object, not a resource handle.

And, you're not performing any error checking on your query. If you were, you'd see that you have mistakenly used single quotes to delimit table and field names, not backticks.

$sql = "INSERT INTO `nlcc_ver1`.`tUsers`
       (`userID`, `userName`, `userPassword`, `userHash`,
        `user_first_name`, `user_last_name`, `user_corps`,
        `is_admin`, `is_trg`, `is_sup`, `is_co`)
       VALUES (NULL, '" . $userName . "', '" . $hash . "', '" . $salt . "', '" .
               $f_name . "', '" . $l_name . "', '" . $corps . "', '" . $admin .
               "', '" . $trg . "', '" . $sup . "', '" . $co . "')";

$hostname_Database = "localhost";
$database_Database = "nlcc_ver1";
$username_Database = "root";
$password_Database = "";

$mysqli = new mysqli($hostname_Database, $username_Database, $password_Database, $database_Database); 
if (mysqli_connect_errno()) {
   printf("Connect failed: %sn", mysqli_connect_error());
   exit();
}

$result = $mysqli->query($sql);
if (!$result) {
   printf("%sn", $mysqli->error);
   exit();
}

echo "Query run. Inserted UserID " . $mysqli->insert_id . "<br />";

I strongly suggest using the manual as your reference. It's quite clear on how to use these functions when you're using either procedural or object-oriented style MySQLi.

Wednesday, October 12, 2022
4

The second parameter of date is a timestamp. Use strtotime() to convert $insertbday.

Change this line:

$insertbday = date("Y-m-d", $insertbday);

to:

$insertbday = date("Y-m-d", strtotime($insertbday));

Update

Also, add single quotes around $insertbday to query:

mysqli_query($con, "INSERT INTO user (bday) VALUES ('$insertbday')");
Saturday, October 29, 2022
2

You need to give the array_shift() the parameter! Look this example:

$stack = array("orange", "banana", "apple", "raspberry");
$fruit = array_shift($stack); // Here you give the parameter
print_r($fruit);

You give the null parameter on array_shift() and you need to change it!

Update:

array_shift() shifts the first value of the array off and returns it, shortening the array by one element and moving everything down. All numerical array keys will be modified to start counting from zero while literal keys won't be touched. Read here for more

Wednesday, October 19, 2022
 
shark
 
4

You can use

function consql(&$con){
  $con=mysqli_connect("host","BDusername","DBPassWord","DB") or die( mysqli_error($con));
}

So this is call by reference and $con can use at any page once you call the function

Or use global $con; before the connection line

Friday, December 9, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share