Jump to content
Larry Ullman's Book Forums

mysqli_fetch_array() error


Recommended Posts

Hi Larry,

In my 'login.inc.php' script, I wrote:

$r = mysqli_query($dbc, "CALL get_users_info_from_carts('$uid')");

if (mysqli_num_rows($r) > 0) {
                    
                   while ($row = mysqli_fetch_array($r,  MYSQLI_ASSOC)) {
                      if ($row['users_id'] == '0')
                       {
                        $usr_id = $_SESSION['user_id'];
                        $r = mysqli_query($dbc, "CALL add_user_to_cart('$uid', '$usr_id', '$e')");
                       }
    
                   }
                }

 

My query for 'get_users_info_from_carts('$uid')' is to select everything from the cart for that particular 'uid'.

When I run the script directly in the phpmyadmin, it works fine and returns the records, but when I run it through the browser, it returns an error saying:

 

 "mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given."

 

There clearly isn't a problem with the query, because when run in phpmyadmin, it executes fine.

I have tried everything, but I just can't seem to find out what the problem is. As I said, the stored procedure query runs fine, but when run through the application, it produces the above error.

Can you help please.

Thanks

 

 

               

Link to comment
Share on other sites

What i am trying to do is when the user logs on, a query is run that returns his shopping cart items, and insert an his user_id and email address into the cart if their fields are empty. That way, we will be able to associate the user and his cart items. That's what i'm trying to implement in the login.inc.php script, but unfortunately, the code that I sent you is not allowing me to do that.

 

$r = mysqli_query($dbc, "CALL get_users_info_from_carts('$uid')");

 

The above line should return all the cart items for the current user_session_id.

 

The following line should retrieve all the names and values of the fields for each row.

 

$row = mysqli_fetch_array($r,  MYSQLI_ASSOC))

 

This is when the problem arises.

 

Is there a better way of doing this?

 

 

 

 

Link to comment
Share on other sites

My inclination is since you're using stored procedures already, put as much logic into the stored procedures as you can. But if you do need the cart contents on this page, that's fine.

I'm a little confused by this line, though:

 if ($row['users_id'] == '0')

I'm not sure why you're quoting a number. Also, if there's no users_id for a cart, would that have a 0 value or a NULL value? I would think the latter, but it depends upon how you defined it. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...