0

Here is some code (snippet) from a function I have that takes a users "user_name" and "password" as parameters.

There is an if else statement that triggers along the way, basically, if there is a value $v, then it look ups the users user_name and password in a table and appends the @gmail part to it (so that the input username matches the email in the database) and if they are equal, it will log them in, otherwise it will display a message stating that there was an error while logging in.

The trouble is, I can't get the error message (the second if) to occur, even though the login sections are working fine.

Can anyone spot something obvious in the statment that would cause the error to never show up when a wrong username and password is input?

Thanks in advance.

stuff comes before this...

        if ( $v )
        {
            $email = $user_name . "@gmail.com";
            $query = "SELECT id, email FROM auth WHERE email = '".$email."'";

            $result = mydb::cxn()->query($query);
            $row = $result->fetch_assoc();
            $user_name = $user_name . "@gmail.com";
            if($row['email'] != $user_name)
            {
                echo '<p style="color: red;">There was an error logging in</p>';
            }   

            else {
                login stuff...
            }
3
Contributors
6
Replies
8
Views
5 Years
Discussion Span
Last Post by LastMitch
2

@Navlag

The trouble is, I can't get the error message (the second if) to occur, even though the login sections are working fine.

You mean this:

if($row['email'] != $user_name){
   echo '<p style="color: red;">There was an error logging in</p>';
 }else if{
   echo 'login stuff...';
 }

What is "$v"? In here: if ( $v )

You haven't establiah $v

Edited by LastMitch: grammer

0

Instead of:

if($v)
{

}

Try using:

if(isset($v))
{

}

I don't know which part the final else statement relates to. mhmh!

0

Yes, I mean this:

if($row['email'] != $user_name){
   echo '<p style="color: red;">There was an error logging in</p>';
 }else if{
   echo 'login stuff...';
 }

Specifically this part:

    if($row['email'] != $user_name){

This goes right above the if ($v) segment. Sorry I was trying to focus on the part where it fails.

    $c = new xmlrpc_client(XMLRPC_CLIENT_PATH, XMLRPC_CLIENT_SERVER, XMLRPC_CLIENT_PORT);

    $c->return_type = 'phpvals';

    $r = $c->send($m);
    if ( !$r->faultCode() )
    {
        $v = $r->value();

And it does enter the if ($v) segment, and does the login correctly, the section that fails is the the second if statement, where it should print out that the username and password are incorrect.

2

@Navlag

Try this:

if(isset($_POST['email']) && isset($_POST['user_name'])){
  echo '<p style="color: red;">There was an error logging in</p>';
 }else if{
  echo 'login stuff...';
 }

It's a bit confusing when you have 2 $user_name:

$email = $user_name . "@gmail.com";
$user_name = $user_name . "@gmail.com";
0

Nope, didn't work. But don't worry about it, I have no idea why it's not working either, it's logically sound.

2

@Navlag

Sorry, I made a typo. The typo is I put else if it should be else:

if(isset($_POST['email']) && isset($_POST['user_name'])){
  echo '<p style="color: red;">There was an error logging in</p>';
}else{
  echo 'login stuff...';
}

Nope, didn't work. But don't worry about it, I have no idea why it's not working either, it's logically sound.

Try this:

<?php
 if (isset($v))
        {
            $email = $user_name . "@gmail.com";
            $query = "SELECT id, email FROM auth WHERE email = '".$email."'";
            $result = mydb::cxn()->query($query);
            $row = $result->fetch_assoc();

            if($_POST['email']){
            echo '<p style="color: red;">There was an error logging in</p>';
            }else{
            echo 'login stuff...';
            }
        }
?>

Can you fetch the data from auth?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.