Kayz Posted April 6, 2007 Share Posted April 6, 2007 Hi all i am doing a project a dummy shopping cart website, i need to make it from scartch, now i have a user db inc password etc and also have a secure area for members to log in etc. Now I just want you guys to tell me if this will work before i begin, i want to know if my theory is correct, what i will do is first: 1. I will have a "item 1, item 2 and item 3" as fields within the the user table. 2. I will have a php page where when the user clicks or wants to add an item to the basket, it will then add the item under their profile i.e. user. 3. So basically when they hit "add" the item name will be inserted into the user db and will show within their basket. When they want to remove the item they can click remove which will then remove the item from the db thus showing the removal within the basket itself also. This is the problem, since the user is inside a big database of other users and when the user logs in his/her name is shown via a variable $ how can i only make it so when that particular users logs in they will only be able to see the items they had purchased under their profile? Otheriwise when the other users login they will see the same item also. If somebody can help me out here, or if they know a better soloution. P.S: I am just after a small dummy cart site which adds items to the users basket and allows the user to remove them also. Also once they do proceed to submit their order, a history of their purchases is shown in their profile. If anybody knows any better ideas it would be much appreciated. Thanks! Kayz Link to comment https://forums.phpfreaks.com/topic/45869-shopping-cart-help/ Share on other sites More sharing options...
reneeshtk Posted April 6, 2007 Share Posted April 6, 2007 Please use a multidimesional array for storing cart items and store the array in session. I belive you know about session. arr[itemcode][quantity]. Link to comment https://forums.phpfreaks.com/topic/45869-shopping-cart-help/#findComment-222840 Share on other sites More sharing options...
boo_lolly Posted April 6, 2007 Share Posted April 6, 2007 this is a very simple project. i suggest becoming familiar with tizag and w3schools tutorials before you attack this project. Link to comment https://forums.phpfreaks.com/topic/45869-shopping-cart-help/#findComment-222881 Share on other sites More sharing options...
Kayz Posted April 7, 2007 Author Share Posted April 7, 2007 So far I have the following mysql table which is fully functional and allows users to register, add to db and also allows users to login/logout: CREATE TABLE contacts ( member_id int(30) NOT NULL auto_increment, firstname varchar(30) NOT NULL default '', surname VARCHAR(30) NOT NULL default '', contact_no INT(11), housename_no VARCHAR(20), address_line1 VARCHAR(20), address_line2 VARCHAR(20), address_line3 VARCHAR(20), city_county VARCHAR(15), postcode VARCHAR(, email varchar(30) NOT NULL default '', username varchar(25) NOT NULL default '', password varchar(255) NOT NULL default '', PRIMARY KEY (member_id), UNIQUE KEY username (username) ) TYPE=MyISAM COMMENT='Members'; I then created the following two more tables as instructed by somebody else which I did today: CREATE TABLE orders ( member_id int(11) unsigned NOT NULL default '0', product_id int(11) unsigned NOT NULL default '0', quantity int(10) unsigned NOT NULL default '0' ); and CREATE TABLE products ( product_id int(11) unsigned NOT NULL auto_increment, product varchar(255) NOT NULL default 'Product Name', code varchar(255) NOT NULL default 'Product Code', price decimal(5,2) unsigned NOT NULL default '0.00', PRIMARY KEY (`product_id`) ); And I have now inserted dummy entries into the “orders” table and the “products” table. INSERT INTO orders VALUES ('1', '1', '2'); INSERT INTO orders VALUES ('1', '3', '1'); INSERT INTO products VALUES ('1', 'Product 1', 'PC1', '12.00'); INSERT INTO products VALUES ('2', 'Product 2', 'PC2', '15.00'); INSERT INTO products VALUES ('3', 'Product 3', 'PC3', '20.00'); Now I am just guessing that I have to do the php bit? How can I get this to work? Ive made connection to the db and now require the rest which is puzzling me. Yes i know a little bit about sessions and keeping the user logged in etc. Remember it needs to be as basic as possible, no need for anything special or any form of security, just plain and simple and bland will do, just need it to work that’s all and I will then integrate it into the site which I already have. I already have a login system in place which works. If somebody can instruct me then id be very greatful, Cheers. Link to comment https://forums.phpfreaks.com/topic/45869-shopping-cart-help/#findComment-223308 Share on other sites More sharing options...
chronister Posted April 7, 2007 Share Posted April 7, 2007 set a session with the users id $_SESSION['member_id']='1'; Once you have the member id, you can run a query to select only those items that this user has added to the cart. $query="SELECT * FROM orders WHERE member_id=' ".$_SESSION['member_id']." ' "; $result=mysql_query($query); this will return only the results for that particular user. Note: I am not sure that I concatenated that string properly as it's 2:30am, and I don't have code coloring right now, so you may have to do that part to avoid errors. Link to comment https://forums.phpfreaks.com/topic/45869-shopping-cart-help/#findComment-223470 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.