PHP和MySQL:mysqli_num_rows()期望参数1为mysqli_result,给定布-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

PHP和MySQL:mysqli_num_rows()期望参数1为mysqli_result,给定布

保持可爱mmm 2020-05-10 18:30:15 62

我正在尝试集成HTML Purifier http://htmlpurifier.org/来过滤我的用户提交的数据,但是下面出现以下错误。我想知道如何解决这个问题?

我收到以下错误。

on line 22: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given 第22行是。

if (mysqli_num_rows($dbc) == 0) { 这是PHP代码。

if (isset($_POST['submitted'])) { // Handle the form.

require_once '../../htmlpurifier/library/HTMLPurifier.auto.php';

$config = HTMLPurifier_Config::createDefault();
$config->set('Core.Encoding', 'UTF-8'); // replace with your encoding
$config->set('HTML.Doctype', 'XHTML 1.0 Strict'); // replace with your doctype
$purifier = new HTMLPurifier($config);


$mysqli = mysqli_connect("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"SELECT users.*, profile.*
                             FROM users 
                             INNER JOIN contact_info ON contact_info.user_id = users.user_id 
                             WHERE users.user_id=3");

$about_me = mysqli_real_escape_string($mysqli, $purifier->purify($_POST['about_me']));
$interests = mysqli_real_escape_string($mysqli, $purifier->purify($_POST['interests']));

if (mysqli_num_rows($dbc) == 0) { $mysqli = mysqli_connect("localhost", "root", "", "sitename"); $dbc = mysqli_query($mysqli,"INSERT INTO profile (user_id, about_me, interests) VALUES ('$user_id', '$about_me', '$interests')"); }

if ($dbc == TRUE) { $dbc = mysqli_query($mysqli,"UPDATE profile SET about_me = '$about_me', interests = '$interests' WHERE user_id = '$user_id'");

    echo '<p class="changes-saved">Your changes have been saved!</p>';

}

if (!$dbc) { // There was an error...do something about it here... print mysqli_error($mysqli); return; }

}

关系型数据库 MySQL PHP
分享到
取消 提交回答
全部回答(1)
  • 保持可爱mmm
    2020-05-10 18:30:34

    $dbc返回假。您的查询中有一个错误:

    SELECT users., profile. --You do not join with profile anywhere. FROM users INNER JOIN contact_info ON contact_info.user_id = users.user_id WHERE users.user_id=3"); Raveren已描述了一般的解决方法。来源:stack overflow

    0 0
数据库
使用钉钉扫一扫加入圈子
+ 订阅

分享数据库前沿,解构实战干货,推动数据库技术变革

推荐文章
相似问题