views:

36

answers:

4

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

+1  A: 

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

BarsMonster
Sorry, could you give a bit more detail?
Rifki
A: 

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';
Scott M.
IM sorry my sql is not too good, but am learning fast. Could you give an example of how to query a premium member using php?
Rifki
http://php.net/manual/en/book.mysql.phpyou are looking for mysql_query() and mysql_fetch_array() or mysql_fetch_assoc()
Scott M.
A: 

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);
'

pr0crastin8r
A: 

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)

JochenJung
thanks for your help
Rifki