Page 1 of 1
im trying to only alow login to those who registered
Posted: Fri Nov 20, 2009 5:06 am
by chris_s_22
when a user registers i insert value 0 into the registered feild in the database then send email with passkey
when someone clicks that email link its send to a page that checks its valid. if its valid it also updates the registered feild in the database to 1
When i login im trying to only alow a user to login if registered
the code im adding to my login function is, can anyone see where im going wrong?
Code: Select all
$query = mysql_query("SELECT registered FROM members WHERE username = '". $username ."'");
$result= mysql_query ($query)
if ($result == 0)
{
// Reshow the form with an error
$usernamereg_error = 'username is not registered';
include 'index.php';
exit;
}
Re: im trying to only alow login to those who registered
Posted: Fri Nov 20, 2009 5:51 am
by dejvos
Hi,
problem is on 5th row. A return value of mysql_query is
NOT a result of query. You have to use mysql_fetch_array between mysql_query and testing of value. It will look like this
Code: Select all
$result = mysql_query("SELECT registered FROM members WHERE username = '". $username ."'");
if(!$result) die('Error occures');
$result = mysql_fetch_array();
if($result[0] === 0){
...
}
Re: im trying to only alow login to those who registered
Posted: Fri Nov 20, 2009 8:40 am
by chris_s_22
still not working must be something else
Re: im trying to only alow login to those who registered
Posted: Fri Nov 20, 2009 8:58 am
by dejvos
Sorry, mysql_fetch_array() needs parameter:
Code: Select all
$result = mysql_query("...");
$result = mysql_fetch_array($result);
Re: im trying to only alow login to those who registered
Posted: Fri Nov 20, 2009 10:06 am
by chris_s_22
i tried that but still lm not having no luck
what is happening is that users can sign in either if they are unregistered or registered.
im getting no error messages. when i check mysql they are definetly 0 if unregistered and 1 if registered.
if its any help if i echo out the $result it displays array
this is exact code im using
Code: Select all
function user_login($username, $password)
{
$result = mysql_query("SELECT registered FROM members WHERE username = '". $username ."'");
if(!$result) die('Error occures');
$result = mysql_fetch_array($result);
if($result[0] === 0)
{
// Reshow the form with an error
$notregistered_error = 'username not registered';
include 'index.php';
exit;
}
Re: im trying to only alow login to those who registered
Posted: Fri Nov 20, 2009 11:31 am
by chris_s_22
i managed to figured it out myself i used this in the end but thx for help
Code: Select all
function user_login($username, $password)
{
$thequery = ("SELECT registered FROM members WHERE username = '". $username ."' ");
$query = mysql_query($thequery) or die ('session data dont match.');
$row = mysql_fetch_array($query);
$result = $row['registered'];
if($result == 0)
{
// Reshow the form with an error
$notregistered_error = 'username not registered';
include 'index.php';
exit;
}