INSERT 查询产生“警告:mysqli_num_rows() 期望参数 1 为 mysqli_result,给定布尔值"

2022-01-09 00:00:00 insert php mysqli

我对收到以下消息的原因感到困惑:

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

mysqli_num_rows() 期望参数 1 为 mysqli_result,给定布尔值

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

这个问题与之前的查询不同,因为我的查询实际上正确执行(确实已将值输入到数据库中).所以,我希望 MySQL 返回一个结果集而不是一个布尔值.

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.

以下是我的功能:

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 {
    }
}

这是错误的部分结果:

[valuesEntered] => values entered
    [insert] => INSERT INTO newsletter (first_name, email ) 
                  VALUES ('name', 'testemail@yahoo.com')
    [R3] => 1

推荐答案

mysqli_num_rows() 函数返回结果集中的行数.对于插入、更新和删除使用 mysqli_affected_rows

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

相关文章