Solar Posted June 3, 2010 Share Posted June 3, 2010 Hello, I am needing of a start to help me make an online little virtual store on my website. Lets say I have a item.table like the following; iditemcostdescription 2Color Name500Color your name anyway you want it to make it stand out on the members list! 1Multi-Color Name1000Color your name anyway you want it to make it stand out on the members list! The only problem where I would have problems is, is the actually buy.. I understand *INSERT* php/mysql so I am fine with that, I will have a seperate list with the item's ID link with my users table.. So my question is, can someone write me a little simple code that will check a user's money in table.users and see if they have enough to purchase an item for table.items when they click buy? If they do not have enough money, then I know how to echo and elseif statement stating that you do not have enough money! Thank you for your help in advanced, I appreciate your time for reading my post. Quote Link to comment https://forums.phpfreaks.com/topic/203805-simple-purchasing/ Share on other sites More sharing options...
TOA Posted June 3, 2010 Share Posted June 3, 2010 The way I see it, you'll want to select the money the logged user has and then check it against the cost of the item, which I'm assuming is stored in a variable(?). Could you post the code you have or have tried? Quote Link to comment https://forums.phpfreaks.com/topic/203805-simple-purchasing/#findComment-1067425 Share on other sites More sharing options...
dabaR Posted June 3, 2010 Share Posted June 3, 2010 Ugh, sounds like you would benefit by using a drupal installation with ubercart, I bet you they implemented all this, and have user points purchases extensions. Otherwise........ $has_enough_money = db_query("SELECT CASE WHEN users.money > items.price THEN 1 ELSE 0 END FROM users, items WHERE users.id = " . db_quote($user['id']) . " AND items.id = " . db_quote($item['id'])); This solution is a little bit conceptual, in that I am not 100% sure it would work, but give it a shot unless you decide to go the pre-built route. Quote Link to comment https://forums.phpfreaks.com/topic/203805-simple-purchasing/#findComment-1067426 Share on other sites More sharing options...
Solar Posted June 3, 2010 Author Share Posted June 3, 2010 The way I see it, you'll want to select the money the logged user has and then check it against the cost of the item, which I'm assuming is stored in a variable(?). Could you post the code you have or have tried? I don't have any code at this time as I working on other parts of my website, Once I am done that I'm going to give this ago. I have no problems, echo'ing the item database its just the BUY button would be my only problem. But variables from checking the user's amount they have and check against the cost of the item is correct. Thanks Ugh, sounds like you would benefit by using a drupal installation with ubercart, I bet you they implemented all this, and have user points purchases extensions. Otherwise........ $has_enough_money = db_query("SELECT CASE WHEN users.money > items.price THEN 1 ELSE 0 END FROM users, items WHERE users.id = " . db_quote($user['id']) . " AND items.id = " . db_quote($item['id'])); This solution is a little bit conceptual, in that I am not 100% sure it would work, but give it a shot unless you decide to go the pre-built route. Like I posted above, I will try to give this ago, it seems to make more sense to me when you put it that way. Thanks If there are any other solutions, I will be gladly to see them as well Quote Link to comment https://forums.phpfreaks.com/topic/203805-simple-purchasing/#findComment-1067428 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.