phgstudy Posted October 10, 2016 Share Posted October 10, 2016 Hello! I'm working on a login form, but the while loop takes longer than 120 seconds to run, and then an expiry error is thrown. Here's the code:- $res=mysqli_query($con,"select username,password from users"); $row=mysqli_fetch_array($res); while($row) { if($username==$row["username"] && $password==$row["password"]) { echo "LOGIN SUCCESSFUL!"; } else { echo "LOGIN Failed!"; } Quote Link to comment https://forums.phpfreaks.com/topic/302309-php-while-lookp-taking-too-long-to-execute/ Share on other sites More sharing options...
benanamen Posted October 10, 2016 Share Posted October 10, 2016 (edited) You are missing a where clause. Your query is selecting all of the usernames and passwords in the whole database. Your whole code is flawed. I'm sure others will give you more feedback. Edited October 10, 2016 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/302309-php-while-lookp-taking-too-long-to-execute/#findComment-1538181 Share on other sites More sharing options...
requinix Posted October 11, 2016 Share Posted October 11, 2016 There really isn't much more to say than that. The query is retrieving every single user in the database. That's slow. If you used a WHERE to only retrieve the user with the matching username then it would happen in less than a second (probably). Well, one more thing. Are you hashing passwords? It doesn't look like it. You need to. 1 Quote Link to comment https://forums.phpfreaks.com/topic/302309-php-while-lookp-taking-too-long-to-execute/#findComment-1538183 Share on other sites More sharing options...
mac_gyver Posted October 11, 2016 Share Posted October 11, 2016 your loop is also looping forever (until the php time limit is reached), since the condition being tested by the loop is a fixed value. you don't even need a loop for what you are doing. your sql query should be trying to match one row, based on the username. if the username/one row is found, you would fetch that one row, then verify if the hashed version of the entered password matches the hashed password from when the user registered. see php's password_hash() and password_verify() functions for this. 1 Quote Link to comment https://forums.phpfreaks.com/topic/302309-php-while-lookp-taking-too-long-to-execute/#findComment-1538186 Share on other sites More sharing options...
davidweb09 Posted October 13, 2016 Share Posted October 13, 2016 please add where in your query for execute it properly. Quote Link to comment https://forums.phpfreaks.com/topic/302309-php-while-lookp-taking-too-long-to-execute/#findComment-1538243 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.