simple VIP list

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
TimmyP
Forum Newbie
Posts: 5
Joined: Sun Feb 22, 2004 1:08 pm
Location: Suffolk, England

simple VIP list

Post by TimmyP »

Hi, i am working on a game at the moment and I thought about adding a VIP list. So you can see if they are online and have a private chat with them, plus a few other features.

I have managed to make it so that you can add players to the VIP list, but you can keep adding that player over and over again and I can't stop it.

Please could somebody help me with like a piece of code that searches for the VIP.
----------------------------------------------------------
i have a database table called 'testa_vips'

with fields 'vip_id','viptarget_id','owner_id'

not sure if thats the right way to go about it.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what code do you have so far? we aren't here to do your "homework" for you.

the search is a simple query in the database, if that's what you are using. If not, start using one.
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

Okay, if I understand well you add (register) data into your database (hopefully you do have a db) and you want to be able to restrain the list to only one vip

First of all how are they entered in the DB ?
with a First name and last name ? or with a username?
In both case the "logic" is the same though.

You first get the username (or fname and lname) you want to enter in your db, then you make a check in your database for the username.
IF you have 1 (or more) rows returned that means the nmame already exist, and you just don t insert the username (or fname lname).
So i'll show you a bit of code.

Code: Select all

<?php
$host = "localhost";
$user = "ROOT";
$pswd = "";
$dbname = "bibi";
   
$connect = mysql_connect($host, $user, $pswd)
   or die("Could not connect: " . mysql_error());
$database = mysql_select_db("$dbname")
   or die(MySQL_Error());

$username = $_POST["username"];
$password = $_POST["password"];

/*this simply look if there’s already the same username in the DB since I decided to have only one possible username, then I set the sql to insert my info IF my username is not taken */

$sql_check = "SELECT * FROM users WHERE username='$username'";
$sql_insert = "INSERT INTO users VALUES ('', '$username', '$password') ";

/*now I execute the query and I put it in a variable*/

$result_check = mysql_query($sql_check) or die(mysql_error());


/*now we are going to get the number of row returned, If there’s 0 that mean there is no other SAME username if it return 1 that means IT ALREADY have this username taken so choose another one*/

$numrow = mysql_num_rows($result_check);
if ($numrow != "0"){    //means if number of row is different than 0
   echo ("Username already taken go back and choose another username please");
}else{
/*Well there is no rows returned with the username entered by the dude, so let’s insert his new info*/
$result_insert = mysql_query($sql_insert) or die(mysql_error());
echo ("Your information has been submitted to the database, Welcome in our super friendly group $username");
}
mysql_close($connect);
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Or since username and user id's will be unique, just make the field that holds the id/username in the VIP table unique - so it can only be in there once.
TimmyP
Forum Newbie
Posts: 5
Joined: Sun Feb 22, 2004 1:08 pm
Location: Suffolk, England

Post by TimmyP »

thanks 4 all the help :D
Post Reply