im trying to only alow login to those who registered

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
chris_s_22
Forum Commoner
Posts: 76
Joined: Wed Dec 31, 2008 2:05 pm

im trying to only alow login to those who registered

Post 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;
}
 
dejvos
Forum Contributor
Posts: 122
Joined: Tue Mar 10, 2009 8:40 am

Re: im trying to only alow login to those who registered

Post 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){
...
}
 
chris_s_22
Forum Commoner
Posts: 76
Joined: Wed Dec 31, 2008 2:05 pm

Re: im trying to only alow login to those who registered

Post by chris_s_22 »

still not working must be something else
dejvos
Forum Contributor
Posts: 122
Joined: Tue Mar 10, 2009 8:40 am

Re: im trying to only alow login to those who registered

Post by dejvos »

Sorry, mysql_fetch_array() needs parameter:

Code: Select all

 
$result = mysql_query("...");
$result = mysql_fetch_array($result);
 
chris_s_22
Forum Commoner
Posts: 76
Joined: Wed Dec 31, 2008 2:05 pm

Re: im trying to only alow login to those who registered

Post 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;
}
 
chris_s_22
Forum Commoner
Posts: 76
Joined: Wed Dec 31, 2008 2:05 pm

Re: im trying to only alow login to those who registered

Post 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;
    }
Post Reply