Rifki
Rifki

Reputation: 901

php/mysql user management

HI

Im trying to figure out a way to differenciate between free users and premium users in a mysql database.

Both users need to register with thier username, password and email. When premium users register though, i need a way of distinguising them from feee uers once in the users table.

Is there a way of autamatically populating a field in the table when a user registers, or am I barking up the wrong tree

thanks

Rifki

Upvotes: 1

Views: 537

Answers (4)

pr0crastin8r
pr0crastin8r

Reputation: 391

First, make new column in your users table:

alter table users add isPremium bool;

I would then assume there is some sort of logical operation you can do on the PHP side that would differentiate free and premium users. For example, maybe the credit card information is set or something. Let's just say you have an $isPremium variable that you set to one or zero depending on those conditions. Your php code should look roughly like this:

$query = "insert into users (username, password, isPremium) values('$username', '$password', '$isPremium');";
mysql_query($query);
'

Upvotes: 0

JochenJung
JochenJung

Reputation: 7213

When a free user signs up, do

INSERT INTO user
  SET username = "$username",
      password = "$password",
      email = "$email",
      premium = 0

for the premium ones:

INSERT INTO user
  SET username = "$username",
      password = "$password",
      email = "$email",
      premium = 1

(don't forget to use addslashes() with username and email; and md5() with the password)

Upvotes: 1

Scott M.
Scott M.

Reputation: 7347

This should add a column on your users table that will let you query if someone is a premium member or not (assuming you are using MySQL):

ALTER TABLE 'users' ADD COLUMN 'premium' ENUM('0', '1') DEFAULT '0';

Upvotes: 0

BarsMonster
BarsMonster

Reputation: 6585

Well, create field 'premium' with default value 0. During premium registration, set it to 1.

Upvotes: 1

Related Questions