Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning when calling mysqli_error() [duplicate]

Tags:

php

mysqli

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.

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 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)
);

Now I get the following error

Not unique table/alias: 'users_categories'

How do I fix this?

Thanks everyone for the help. Is there a way i can reward every one for there help here on stackoverflow instead of one person?

like image 945
123abc Avatar asked Mar 10 '26 18:03

123abc


1 Answers

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

print mysqli_error();

to

print mysqli_error($mysqli);

Once you make the correction, you'll be able to see the error message and debug further.

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.

like image 61
Asaph Avatar answered Mar 13 '26 09:03

Asaph



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!