blocking re-registration using id that are already in the DB

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
omegahawk
Forum Newbie
Posts: 4
Joined: Sat Apr 05, 2003 9:17 pm

blocking re-registration using id that are already in the DB

Post by omegahawk »

he there..
just want to know how to make a query from php to mysql to check whether the user is already registered or not
.. as the registration requires that only those who have their id's in the database can register...
any suggestions?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

$query = 'SELECT count(*) FROM <table> WHERE <condition>';
$result = mysql_query($query, $connection) or die(mysql_error());
$num = array_shift(mysql_fetch_row($result));
if ($num == 0)
{
	// no such record
}
omegahawk
Forum Newbie
Posts: 4
Joined: Sat Apr 05, 2003 9:17 pm

hmm...

Post by omegahawk »

$query="SELECT idnum, password FROM detail WHERE idnum='$idnum' and password='$password'";

// Run query:
$result=mysql_query($query, $link) or die("MySQL query $query failed. Error if any: ".mysql_error());

// If that idnum already have the password, issue an error message:
if( ($row==mysql_fetch_array($result)) ){
$messages[]="Id No#\"".$_POST["idnum"]."\" already registered. Thank You";
}

here what i did but this only works if the user enters the same password, if he give another password an error will be created in the database... what i want is what to be put in the <condition> so that it will check whether that idnum already have a password or not.. in simple way the registered user cannot re-regist again. the idnum is initially is in the database.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

:?: Please explain what relationship there is between the user and the fields idnum and password
omegahawk
Forum Newbie
Posts: 4
Joined: Sat Apr 05, 2003 9:17 pm

Post by omegahawk »

for the user to register. his idnum must be in the database.

so, when he want's to register, php first will check either his id is in the database or not (im ok with this codes)

and if his id is there..

the php will check whether the user id is already registered.

commonly poeple will check for username, but this is a different case,
i want to check whether the id already have a password or not.
( i have problem with this part)
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

$query = "SELECT idnum, password FROM detail WHERE idnum='$idnum'";
$result = mysql_query($query);
$data = mysql_fetch_array($result);

//-------
if(!isset($data['password']))
{
//reject
}

Another option is to also set a default password field, but if a user worked out what the default is then that would be a security risk
Post Reply