Jump to content
Larry Ullman's Book Forums

dmx1

Members
  • Posts

    70
  • Joined

  • Last visited

Everything posted by dmx1

  1. Hmm....It seems to be working fine for all your stored procedures that I am executing.
  2. 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
  3. 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!!
  4. Hi Larry, I have solved the problem now!
  5. 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 ;
  6. 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.
  7. 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!!
  8. 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.
  9. 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
  10. 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
  11. 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!
  12. 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!
  13. 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
  14. 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
  15. Hi Larry, Happy New Year! Hope you had a great festive season! Larry, I am still learning php and mysql, so please forgive me if the questions seem really basic, but I've tried to research and understand certain concepts, but I'm still confused. My understanding of foreign keys in a database is that: 1) They provide referential integrity. 2) It is used to link two tables together. 3) It will ensure that a table referencing another table will always be referencing a row that exists in its own table, and a table will never be orphaned. Now in your book: 'PHP and MySQL for Dynamic Web Sites' which I purchased recently. On page 198, you created a foreign 'customer_id' key in the 'accounts', table that references the 'customers' table. I understand this concept and it makes sense. But on page 170 in the 'Effortless E-Commerce' book, you again, created a foreign 'customer_id' key in the 'orders' table that references the 'customers' table on page 169. So you have different methods and approaches in both books, but they do the same thing! I'm really confused by this because i'm thinking: 1) How can the foreign 'customer_id' key in the 'orders' table, on page 170('Effortless E-Commerce'), reference the 'customers' table without explicitly referencing it like how you did it on page 198 in the 'PHP and MySQL for Dynamic' book? 2) I've never seen a foreign key get created in this way on page 170 in 'Effortless E-Commerce' book, so can you explain to me i) How this works, ie, how does the database knows 'customer_id' is a foreign key, and that it is referencing the 'customers' table on page 170, without you explicitly writing it. I looked in phpmyadmin, and looked in the designer veiw of your database, but there are no links or relationships demonstrated, or shown between any of the tables, even though the diagram on page 167 in the 'Effortless E-Commerce' book, clearly states that there a one-to-many relationship between the tables. 3) So why doesn't the tables in the Ecommerce2 database in phpmyadmin (in the designer veiw, or even in the database tables), not reflect or show the one-to-many relationships that you have stated exists between the tables on page 167. Thank you in advance regards
  16. Hi Larry, On page 168 in the first version of your ecommerce book, you said that you won't have a login form, like the first project. You also said that there will be no session id's, and instead by storing the customer's shopping cart contents and wish-list items in the database, the customer can leave and return and still have the previous actions recorded and available without ever logging in. My query is, "the customer can leave and return and still have the previous actions recorded and available without ever logging in", only applies if the customer is returning to the same computer, and taking into account that nobody else has used the same computer to add products to their own wishlist or shopping cart. Whereas with a login form, all the user has to do is login with their details, and all of their personalised information, ie saved shopping carts, will automatically return, regardless of how many users have used the same computer to browse and store their own items in their own shopping carts, and their saved history can be accessed remotely. Also, if the user goes to a completely random computer, their saved shopping cart or wish list items will not be visible or recorded. They will only be visible or recorded from the computer where they saved their items, and that's considering no one else has overridden their saved items, by adding their own. So: 1) Is their a way that a user's shopping cart and wish list history can be saved, and re-called from any random computer, and not be overridden if someone else decides to use the same computer to store their own items, because I want an amazon style shopping cart where the user can access their saved shopping cart and wish list history from any computer. 2) If the answer is no for question 1, how hard would it be to implement the login form from the 1st project into the 2nd ecommerce project? I hope my understanding is correct. regards Devon
  17. Larry, Thank you for this! I now understand. For some reason, I thought that $live was automatically changed from false to true, from some other part of the code in the application. I didn't realise I had to manually change the $live constant myself. Now onto understanding the rest of the code......Here goes!
  18. Hi Larry, Thanks for your quick response. I think the logic is my main issue here. So this is my understanding: (!$live) means NOT False, which in turns means TRUE. So on page 61 'if (!$live)' means if($live is NOT False) ie TRUE then do whatever............... This is where I had problems understanding what was going on. So my understanding now is; if (!$live) evaluates to True, then $live must still be False, which in turn means that it is still in development mode and not live. If (!$live) evaluated to False, this would mean that $live would be True, which would mean the site is live. I hope my understanding is correct, because it took me pacing up and down for a good while to understand what is going on. My Final questions is: QU 1: When the site does indeed go live, on what page in the book, or where in the script does TRUE get assigned to the $live variable to signify a change from development to live mode? QU 2: How does the site know when it indeed does go live? QU 3: What piece of code is used to see if the site is live, and where does this code reside? Hope the above made sense. Thanks Larry
  19. Hi Larry, Newbie questions: On page 60, I am getting slightly confused. $live is set to False 1) So in effect is this saying that we set the $live variable to False, so this equates to the site not being live(production mode), but in development mode(localhost)? Now on page 61 it says: if(!$live) Since $live is set to False in the config file, !$live equates to True(1), because NOT false is True. 2) So does 'if (!$live)' equate to: if(true == true) because (!$live) == !FALSE == TRUE 3) How does the site detect if it is live(in production mode) or in development mode(localhost)? So let me know if my understanding of what you wrote is correct. On page 60 i. You set $live to False to indicate that the site is not live ii. If the site is live, or in production mode, $live is set to True, which is represented in the else statement on page 61 4) Where does it then assign True to $live if the site is in production mode? Sorry for the basic questions, but I am still learning. Thank you
  20. Hi, I am a newbie, so please excuse any simple errors I may be making. The address for my php site is: http://localhost:8888/headbands1/ All my files are in the 'headbands1' root directory, such as the 'include', 'views', 'shop', 'sales', index.php. I have a file called '_.htaccess.txt' also in the 'headbands1' directory. I don't know if I really need to include the '_.htaccess.txt' file or not. It has the following information in it: <IfModule mod_rewrite.c> RewriteEngine on # For sales: RewriteRule ^./shop/sales/?$ sales.php # For the primary categories: RewriteRule ^./shop/([A-Za-z\+]+)/?$ shop.php?type=$1 # For specific products: RewriteRule ^./browse/([A-Za-z\+\-]+)/([A-Za-z\+\-]+)/([0-9]+)$ browse.php?type=$1&category=$2&id=$3 # For HTTPS pages: RewriteCond %{HTTPS} off RewriteRule ^./(checkout\.php|billing\.php|final\.php|admin/(.*))$ https://%{HTTP_HOST}/$1 [R=301,L] </IfModule> When I click on an image, on the home page, I get an error saying: 'The requested URL /shop/sales/ was not found on this server.' The shop.php and sales.php pages have not been edited in any way. Can you tell me what I can do, so when I click on the 'Sales Item' image, on the home page, I will not get the above error, and it will take me to the correct page. Thanks
×
×
  • Create New...