kendris Posted February 7, 2013 Share Posted February 7, 2013 I had been following this tutorial (roughly) however i cant seem to get the "true" message or any other message to return on output, any ideas? flexiflash.zip Quote Link to comment https://forums.phpfreaks.com/topic/274145-login/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 7, 2013 Share Posted February 7, 2013 You didn't state at what point you didn't get the expected output, but I'll assume you meant to tell us it's when you browsed to the login.php file. You are not getting the 'true' message because your conditional test is not true. Your user_exsists() function (in core/database/users.php) is returning the mysql_query() return value for a SELECT query. From the documentation for mysql_query() - For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error. There's two problems with your logic in login.php. A query result resource is equal (two == signs) to true, but it is not exactly (three === signs) a true value. Also, a select query that runs without returning a FALSE value, due to an error, doesn't mean that the query matched any row(s). It just means that the query didn't fail to run. After you test if the query executed without any errors, you must test if the query matched the row(s) you expected it to or returned the value you expected it to. The code you have in the user_exists() function (in core/functions/users.php), does test if the query counted one matching row and returns exactly a true or false value. Why didn't you use the logic in that function? Also, for the user_exists() function in core/functions/users.php. Why do you have two sets of logic in that function. When the first return statement is executed, that code returns to the calling code and nothing in that function after that point will run. Lastly, If that tutorial is showing you that you need to test if the boolean value returned by a function is a true or a false value, I would find a different tutorial. A function that's been defined to return a boolean value, is intended to be used directly in a conditional test. Doing things like empty($username) === true ... user_exists($username) === false is just wasting typing time and processing time. For those two examples, you directly just test if(empty($password)) ... if(!user_exists($username)). Quote Link to comment https://forums.phpfreaks.com/topic/274145-login/#findComment-1410720 Share on other sites More sharing options...
kendris Posted February 7, 2013 Author Share Posted February 7, 2013 Yes sorry it should display at login.php I had been following the tutorial to the letter, currently I'm trying to find a tutorial that will show me how to register a unique user and log in, it should have some minor security so the user will only be able to see pages if logged in. Would you be able to suggest a different tutorial? The functions were put in basically because the tut told me to. Quote Link to comment https://forums.phpfreaks.com/topic/274145-login/#findComment-1410805 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.