Warning when calling mysqli_error ()

Possible duplicate:
PHP warning help?

I am trying to join three tables from a database to display the categories selected by users, but I am getting the following error.

Warning: mysqli_error() expects exactly 1 parameter, 0 given in

I think I am doing something wrong when I query my database.

Here is the code below.

// 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>';
            }

    }

Here is my MySQL table 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)
);

Now I get the following error

Not unique table/alias: 'users_categories'

How to fix it?

Thank you all for your help. Is there a way that I can reward everyone for their help here on stackoverflow instead of one person?

+3
source share
5 answers

You forgot to pass the required argument to mysqli_error () . Change

print mysqli_error();

to

print mysqli_error($mysqli);

.

FYI: , OO mysqli. .

+4

mysqli_error :

if (!$dbc) {
    print mysqli_error($mysqli);
}   

:

. , FROM . FROM users? users , FROM JOINs.

SELECT users.*, categories.*, users_categories.* 
FROM users
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
+2

, mysqli_error, SQL:

  • users_categories users .
  • ON , .

:

SELECT users.*, categories.*, users_categories.*
FROM users_categories
INNER JOIN users ON users_categories.user_id = users.user_id 
INNER JOIN categories ON users_categories.category_id = categories.id
WHERE users_categories.user_id=3
+1
source

mysqli_error link required, try:

print mysqli_error($mysqli);
0
source

This request is a problem. First check the query in PhpMyAdmin or any other mySQL client that you have, and you will see that it does not work.

0
source

Source: https://habr.com/ru/post/1722130/


All Articles