dmx1 Posted May 21, 2019 Share Posted May 21, 2019 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 More sharing options...
Larry Posted May 22, 2019 Share Posted May 22, 2019 My guess is the MySQL user you're using from the PHP script doesn't have execute permissions to run the stored procedure. Link to comment Share on other sites More sharing options...
dmx1 Posted May 22, 2019 Author Share Posted May 22, 2019 Hmm....It seems to be working fine for all your stored procedures that I am executing. Link to comment Share on other sites More sharing options...
dmx1 Posted May 22, 2019 Author Share Posted May 22, 2019 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 More sharing options...
Larry Posted May 23, 2019 Share Posted May 23, 2019 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 More sharing options...
Recommended Posts