调用mysqli_error()时发出警告 [英] Warning when calling mysqli_error()
问题描述
可能重复:
PHP警告帮助?
Possible Duplicate:
PHP warning help?
我试图从数据库中联接三个表以显示用户选择的类别,但是出现以下错误.
I'm trying to join three tables from a database in-order to display a users selected categories but I get the following error.
Warning: mysqli_error() expects exactly 1 parameter, 0 given in
查询数据库时,我认为我做错了事.
I think I'm doing something wrong when I query my database.
这是下面的代码.
// Query member data from the database and ready it for display
$mysqli = new mysqli("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"SELECT users.*, categories.*, users_categories.* FROM users_categories INNER JOIN users_categories ON users_categories.user_id = users.user_id JOIN categories ON users_categories.user_id = users.user_id WHERE users_categories.user_id=3");
if (!$dbc) {
// There was an error...do something about it here...
print mysqli_error();
}
//Users entered category loop
while ($row = mysqli_fetch_assoc($dbc)) {
if (! empty($row['category'])) {
echo '<div class="skill-info">';
echo '<p>' , htmlspecialchars($row['category']) , '</p>';
}
}
这是我的MySQL表结构.
Here is my MySQL tables structure.
CREATE TABLE users (
user_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
user_name VARCHAR(255) NOT NULL,
PRIMARY KEY (user_id)
);
CREATE TABLE categories (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
parent_id INT UNSIGNED NOT NULL DEFAULT 0,
category VARCHAR(255) NOT NULL,
url VARCHAR(255) NOT NULL,
PRIMARY KEY (id),
INDEX parent (parent_id)
);
CREATE TABLE users_categories (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
user_id INT UNSIGNED NOT NULL,
category_id INT UNSIGNED NOT NULL,
PRIMARY KEY (id)
);
现在我遇到以下错误
Not unique table/alias: 'users_categories'
我该如何解决?
感谢大家的帮助.我有什么办法可以奖励每个人,因为他们在stackoverflow上提供的帮助而不是一个人吗?
Thanks everyone for the help. Is there a way i can reward every one for there help here on stackoverflow instead of one person?
推荐答案
您忘记将必需的参数传递给 mysqli_error().更改
You forgot to pass a required argument to mysqli_error(). Change
print mysqli_error();
到
print mysqli_error($mysqli);
进行更正后,您将能够看到错误消息并进行进一步调试.
Once you make the correction, you'll be able to see the error message and debug further.
FYI:看来您奇怪地混合了mysqli的OO和过程样式用法.您应该坚持一个或另一个.
FYI: It looks like you're oddly mixing the OO and procedural style usage of mysqli. You should stick to either one or the other.
这篇关于调用mysqli_error()时发出警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!