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?
blocking re-registration using id that are already in the DB
Moderator: General Moderators
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
}hmm...
$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.
// 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.
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)
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)
$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
$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