Jump to content

Simple Purchasing


Solar

Recommended Posts

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.