Page 1 of 1
simple VIP list
Posted: Wed Sep 01, 2004 3:03 am
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.
Posted: Wed Sep 01, 2004 9:48 am
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.
Posted: Wed Sep 01, 2004 9:59 am
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);
Posted: Wed Sep 01, 2004 11:15 am
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.
Posted: Wed Sep 01, 2004 3:11 pm
by TimmyP
thanks 4 all the help
