Jump to content
Larry Ullman's Book Forums


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About dmx1

  • Rank

Recent Profile Visitors

265 profile views
  1. 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?
  2. Hmm....It seems to be working fine for all your stored procedures that I am executing.
  3. 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
  4. No items were being added to the cart for some strange reason. The structure looked fine, so I didn't understand why no items were being added. I put the default value of the user_id in my cart table, which is an int, as NULL. This is not allowed. The default value should be '0'. After I adjusted it, it worked fine!!
  5. Hi Larry, I have solved the problem now!
  6. Hi Larry, Regarding the stored procedure on page 231, which is below DELIMITER $$ CREATE PROCEDURE add_to_cart (uid CHAR(32), usr_id INT(6), type VARCHAR(12), pid MEDIUMINT, qty TINYINT) BEGIN DECLARE cid INT; SELECT id INTO cid FROM carts WHERE user_session_id=uid AND product_type=type AND product_id=pid; IF cid > 0 THEN UPDATE carts SET quantity=quantity+qty, date_modified=NOW() WHERE id=cid; ELSE INSERT INTO carts (user_session_id, users_id, product_type, product_id, quantity) VALUES (uid, usr_id, type, pid, qty); END IF; END$$ DELIMITER ; I am trying to modify the original 'add_to_cart' procedure by adding the parameters 'usr_id' and 'em' parameters, which represent the user id and email from the users table. In the carts table, I put these values as DEFAULT NULL. Every time I press the 'add to cart' button, no items are added to the shopping cart. The message that is shown is 'The Shopping Cart is Empty' I have tried to figure out why no items are being added to the shopping cart. I know the problem is with the 'add_to_cart' procedure that I have modified, because when I add the original procedure, items are added to the shopping cart, which is what I want. But for some reason, my modified version is not working. I have only added an extra two parameters, but this somehow, stops items from being added to the shopping cart. Can you let me know what I am doing wrong please. My modified version of the 'add_to_cart procedure is below. Thanks DELIMITER $$ CREATE PROCEDURE add_to_cart (uid CHAR(32), usr_id INT, em VARCHAR(80), type VARCHAR(12), pid MEDIUMINT, qty TINYINT) BEGIN DECLARE cid INT; SELECT id INTO cid FROM carts WHERE user_session_id=uid AND product_type=type AND product_id=pid; IF cid > 0 THEN UPDATE carts SET quantity=quantity+qty, date_modified=NOW() WHERE id=cid; ELSE INSERT INTO carts (user_session_id, users_id, email, product_type, product_id, quantity) VALUES (uid, usr_id, em, type, pid, qty); END IF; END$$ DELIMITER ;
  7. I read your comments again, and undestand the scenario! Basically, a session id is generated on every different computer that the user visits, so they could end up with a situation where there are multiple items in the cart which multiple user_session id's. What I would do is retrieve the items based on the user's current email address, and NOT session id. This way, all the items stored in the database which is linked to the user's email address, but different session id's would still be returned. I could overwrite all the previous user_session id's already stored in the database with the current session id, if the user logged in from a different computer, in order to account for that scenario. My confusion came because I thought the session id was only generated when the user logged in, as opposed to being generated automatically, when they visit the site.
  8. Hi Larry, How you have explained it is exactly how I was intending to do it. Regarding the last scenario where the user has populated two carts, one while logged in on computer A previously and another while not logged in on computer B. Shopping cart items will only be recorded in the database and attached to the user's email if the user has logged in. If the user adds items to the shopping cart without logging in, and then goes to another computer and then logs in, the items added to the cart without logging in won't be shown in their cart if they log into another computer. So basically, the user has to log in, in order for the shopping cart items to be recorded in the database, and in turn can be accessed from any computer. Also, if the user adds items to the shopping cart, and then logs in or registers, their email address will automatically be sent to the email column in the cart table and associated with the session id in the cart table. Hope I understood the scenario correctly and what I said makes sense!!
  9. Hi Larry, The reason I don't want to depend on the session ID for primary access to the cart when logging in, is because the user might access the site from a completely different computer, which then renders the session ID useless in terms of retrieving the cart items. Whereas if the user stores their email address in the cart, then whatever computer or wherever the user accesses the site, and then logs in, the user's shopping cart items will be retrieved, based on the user's email address and NOT the user's sesssion id( which would only come in handy if they access the site from the same computer where the session id is stored, also assuming no one else visited the site after them). Larry, my logic could be totally flawed, so forgive me if what I said makes no sense.
  10. Hi Larry, Thanks for the response! What I was thinking of doing is adding the user's email address to the Cart table. So the Cart table would now have an extra column, ie email, wIth a DEFAUL NULL value. The logic would be: A random user visits the website, they then start adding items to the Cart, without registering or logging in. So now the Cart has items in it, with no user information, ie email or user id, only the session id, along with product information. The email address column in the Cart table is blank(DEFAUL NULL). The user then registers, or logs in, and the email address is automatically sent to the empty email column in the Cart table. This email address is now connected to the session id, which resides in the current Cart table. So now all the products with a particular session id, is now tied to the user via the unique email address in the Cart table. So now if the user logs off, and logs back on a different computer, the logic would be, retrieve all items from the shopping Cart table, for the currrent email address(which pertains to the current user). So the shopping cart page will display all the items from the Cart table for that user, which would be unique to that user because of their unique email address. If the user then logs off, we can run the same query, which is, retrieve all the items from the shopping Cart table, for the current email address. Because the user has now logged off, the email value would be an empty string or null. So therefore, no items would be retrieved for a null email address. The page would then display, "The shopping cart is empy." Can you let me know if this logic sounds correct, and I would therefore only have to add the user's email address in the Cart table to achieve the above logic. Thanks
  11. Hi Larry, Hope you are well. I managed to implement the login system from the first site, into the 2nd ecommerce coffee site. My question is: 1) How would I connect the user's unique session id, with the their saved shopping cart items, so if the user logs out, and goes to a completely different computer and logs back in, his stored shopping cart items will reappear? Thanks regards
  12. Hi Larry, I am trying to implement the login functionality from the first part of your book(Effortless E-Commerce), into the second part, which is the ecommerce site. I know you said we can use the login functionality from the first part of your book and transfer it to the ecommerce site, but as a newbie, I'm struggling a bit. So I was wondering if you had any advice on the best way to implement registration and login functionality into the coffee site. Specifically, I would want the user's shopping cart items to be retrieved at any time, even when the user has logged off, and logged back in again, based on the user's unique session id. Hope you can help. Thank you!
  13. Hi Larry, I found the error. Thanks for your response! Also Larry, could you possibly answer my foreign key question in my earlier post because I still don't understand your interpretation of how you made the joins between the foreign key and parent table, without explicitly declaring the connection in your sql script. Thank you!
  14. Hi Larry, When I click the 'Sales Items' link on the home page, I get the following error: Current Sale Items An error occurred in script '/Applications/MAMP/htdocs/views/list_sales.html' on line 29: Undefined index: description Array ( [0] => Array ( [file] => /Applications/MAMP/htdocs/views/list_sales.html 1) Can you tell me why I am getting this error? 2) Can you tell me how to resolve this error? Thank you regards
  15. Hi Larry, I just saw your message! Didn't think you were going to reply so I didn't bother to check up! No problem anway! Yes, I'm still really confused, because in sql, as I understand it, a reference to a FOREIGN key has to be explicity created, so in your example I'm really confused as to how the Foreign key references are created! Thanks
  • Create New...