Jump to content

login


kendris

Recommended Posts

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)).

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.