tags:

views:

108

answers:

5
function check_login($array_val)
   {


  $strQury = "Select * from  tblsignup where usr_email ='".$array_val[0]."' and usr_password  = '".$array_val[1]."'" ;

    $result  = mysql_query($strQury);
    $row_user = mysql_fetch_array($result);
    if(mysql_num_rows($result)>0)
     {
      $msg = "true";

     }
    else
     {
      $msg = "false";
     }
    return $msg ;
   }

The return value is Object id #1true???? what is object id#1?

+1  A: 

Try this:

function check_login($array_val)
{
    $strQury = "Select * from  tblsignup where usr_email ='".$array_val[0]."' and usr_password  = '".$array_val[1]."'" ;

    $result  = mysql_query($strQury);
    $row_user = mysql_fetch_array($result);

    if(mysql_num_rows($result)>0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

Let us know what result you get when using that code.

Ian P
Unfortunately, the two codes should produce the same exact result.
msakr
Why exactly do you need to put the return false inside an `else`? ;-)
Itay Moav
They shouldn't product the same result. @Itay -- you don't. It's just habit :)
Ian P
Why use an if structure at all?`return mysql_num_rows($result)>0;`
Jeroen Pelgrims
@ Jeroen now return value is: Object id #10
Aamir
@mahmoudsakr same out put by this method.
Aamir
+2  A: 

You're returning the strings "true" or "false" when you probably mean the boolean values true and false.

Oh, and your code is wide open to a visit from Little Bobby Tables. You really should use mysqli and proper prepared statements instead.

Michael Borgwardt
i musing mySql not mysqli
Aamir
@aamir: mysqli is just a different (and much superior) alternative to the regular mysql PHP extension.
Michael Borgwardt
A: 

user single quotes and things will start to work better. also check your query for sql injection bug as it does have it.

Elijah
by single quotes problem still...
Aamir
+4  A: 

Change from:

echo $objUser.check_login($array_login);

to:

echo $objUser->check_login($array_login);

The . operator in PHP does string concatenation, while the arrow allows you to access object methods and attributes.

erisco
There is of course the weird question of why `check_login()` returns anything at all if it is actually a method of `$objUser`. Why not a fatal error? My guess is that aamir Fayyaz has been moving code around trying to get things working and moved `check_login()` outside of the class when he got the fatal error using the concatenation operator.
erisco
my check_login() method in a classUser,when i used echo $objUser->check_login($array_login);the displayed page is blank, it never move to function of class,
Aamir
Ahh, nice catch. @aamir Fayyaz: you should`echo check_login($array_login);`
msakr
A: 

Change

echo $objUser.check_login($array_login);

to

echo $objUser;
echo check_login($array_login);

You should end up with the following result:

Object id #1
true

My guess is that $objUser was set earlier with something along these lines:

$objUser = new User;

As a result, it is an object (the first one declared) and will return Object id #1 when you just echo it. You will need to read up on classes to understand that more.

Joseph
me using$objUser = new classUser();to creat an object.
Aamir
exactly. The `check_login()` function I am guessing is not part of the object or erisco's solution would have worked. You cannot simply echo an object. It is not a string or a number. It is a collection of data organized in a specific way. If you just use `echo check_login($array_login);` does it give you the result you are looking for?
Joseph
thanks to all, i solve it...
Aamir
Then either post the solution, delete the question, or accept the answer that helped the most so that the people that come next with the same problem can see what the solution is.
Joseph
There is brace problem, the function define outside the class by miss take....
Aamir