mysqli_affected_rows()期望参数1为mysqli,给定对象 [英] mysqli_affected_rows() expects parameter 1 to be mysqli, object given

查看:109
本文介绍了mysqli_affected_rows()期望参数1为mysqli,给定对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为表单进行服务器端验证.表单使用AJAX将用户名"输入字段中的值发送到我的php页面,然后检查该用户名是否已存在于数据库中.

I am working on making server side validation for a form. Using AJAX, the form sends the value in the input field for 'username' to my php page which then checks to see if this username already exists in the database.

这是我的php代码:

$result = mysqli_query($dblink, "SELECT * FROM users WHERE `username` = '$regname'") 
or die(mysqli_error($dblink));
echo mysqli_affected_rows($result);

*(此刻,我正在为mysqli_affected_rows做一个简单的回显,以查看我的MySQL查询是否按预期工作)*

*(At the moment I am doing a simple echo for the mysqli_affected_rows just to see if my MySQL query is working as intended)*

我得到的错误是:

警告:mysqli_affected_rows()期望参数1为mysqli,第20行的/Users/test/Sites/proj/formvalidate.php中给出的对象

Warning: mysqli_affected_rows() expects parameter 1 to be mysqli, object given in /Users/test/Sites/proj/formvalidate.php on line 20

我不太确定此错误试图告诉我什么.根据我所搜索的,对象"是对OOP编程方法的引用,但是(据我所知)在这个特定示例中我没有使用OOP概念/原理吗?还是我误解了此错误消息?

I am not quite sure what this error is trying to tell me. From what I have Googled "object" is a reference to OOP programming methods, but (as far as I know) I am not using OOP concepts/principles in this particular example? Or did I misinterpret this error message?

谢谢.

推荐答案

实际上,您不是要传递$resultmysqli_affected_rows,而是要传递DB链接(由返回),该链接将为您提供受上一个查询影响的行.参见:

Rather than passing $result in to mysqli_affected_rows you actually want to pass the DB link (returned by mysqli_connect) which will give you the number of rows affected by the previous query. See:

http://uk.php.net/mysqli_affected_rows

这篇关于mysqli_affected_rows()期望参数1为mysqli,给定对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆