Members Section With Credit Management

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
indy10
Forum Newbie
Posts: 1
Joined: Tue Jan 05, 2010 11:57 am

Members Section With Credit Management

Post by indy10 »

Hi All,

This is my first post, so please accept my apologies if it is in the wrong section.

I am trying to create a website that has a members area with the functionality to allow members to make a purchase based on the number of credits they have.

My problem is understanding how I can create a solution that verifies if enough credits are there.

Basically a member would subscribe to the website, and would be granted access to the members area. The products on sale are download based so the member would be able to preview the file (with the sensitive/valuable information ommitted). They can then buy credits from the site, and can purchase products using the credits they have bought.

What I don't get, is how I allocate their purchase as a credit to their own account, and how I deduct the correct credits when a purchase is made - which then releases the whole product.

I hope that makes sense and I really appreciate any advice anyone can offer.
eFishy
Forum Newbie
Posts: 9
Joined: Tue Jan 05, 2010 12:26 pm

Re: Members Section With Credit Management

Post by eFishy »

Basically you need some kind of database, I would recommend mySQL.

Each user will have a record in the database for example called users containing:
username, password, email, credits

If someone buys credits you would do something like...

Code: Select all

// Get Current Credit Level
$result = mysql_query("SELECT * FROM users WHERE username='".$username."' ")or die(mysql_error());  
$row = mysql_fetch_array( $result );
$NewCreditLevel = $CreditsToAdd + $row['credits']; // Add the new credits to old credits
// Update the credit
$result = mysql_query("UPDATE users SET credits='".$NewCreditLevel."' WHERE username='".$username."'") or die(mysql_error());


And when they spend credits just change

Code: Select all

$NewCreditLevel = $CreditsToAdd + $row['credits'];
to

Code: Select all

$NewCreditLevel = $CreditsToTake - $row['credits'];
You would also need to add parts in to make sure they have enough credits to cover the cost, otherwise they would be getting minus figures.

Hope that helps a bit...
Post Reply