Jump to content

[SOLVED] a function to check logins! doesn't return false!


samoi

Recommended Posts

Hello guys

 

I have this function

function phonebook($u, $p)
{
    $query = "SELECT * FROM eid WHERE phone = '" . $p . "' OR user = '" .
        $u . "'";
$result = mysql_query($query) or die(mysql_error("Error result"));
    $row = mysql_fetch_row($result) or die(mysql_error("Error row"));
    return $row;
}

 

and this if statement

 

if (isset($_POST['book'])) {

    $user = $_POST['user'];
    $phone = $_POST['phone'];
phonebook($user, $phone);
    if (phonebook($user, $phone)) {
        $_SESSION["user"] = phonebook($user, $phone);

        echo "The contact id is " . $_SESSION["record"][0] . " And the number is " . $_SESSION["record"][1];
    } else {
        echo 'No record'; // To tell the user there was no record
    }


}
else {
// Get the user out to search.php page again
}

 

Please help me with debug the problem!

 

Thank you all!

 

 

 

Please note, I am doing this to learn only! no purpose behind all of this! I wanted to do some functions and learn with it.

You don't use die("Error") to return 1; (I'm pretty sure, but it might be return 0;)

 

wow ! :)

 

thank you for the speed reply!

But as I stated above, that I want to learn doing the functions!

I did not understand what you meant!

also I noticed return with 1 and 0 values in many scripts! what does that mean?

 

Thank you and sorry for being asking too much!

Ok, return will stop the function as soon as it's executed, and whatever is in the return (like, return $var or return "This") gets passed outside. I'll show you an example

 

function Test()
{
$Var = "Hello World";
return $Var;
}

echo Test();

 

That would echo "Hello World" Or you could do this

 

function Test()
{
return "Hello World";
}

$Var = Test();
echo $Var;

 

That would also echo Hello World.

 

Now, if you were to use return 1, that wouldn't return a string, but you could use an if function. I'll show you

 

function Test()
{
$Var = "On";
if($Var == "On")
	{
	return 1;
	}
else
	{
	return 0;
	}
}

if(Test())
{
echo "Function is Working";
}
else
{
echo "Error";
}

 

Try it, it should work. 1 is for success, 0 is for error

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.