samoi Posted September 25, 2009 Share Posted September 25, 2009 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. Quote Link to comment Share on other sites More sharing options...
Garethp Posted September 25, 2009 Share Posted September 25, 2009 You don't use die("Error") to return 1; (I'm pretty sure, but it might be return 0;) Quote Link to comment Share on other sites More sharing options...
samoi Posted September 25, 2009 Author Share Posted September 25, 2009 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! Quote Link to comment Share on other sites More sharing options...
Garethp Posted September 26, 2009 Share Posted September 26, 2009 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.