Zeehamster Posted August 1, 2017 Share Posted August 1, 2017 (edited) I'm trying to write a code that will check the Database at the user for the approval if the approval = 0 i do not want the user to log in if the approval = 1 i do want the user to log in But i cant get it done, tried all sorts of code but cant get the correct one. Maybe you guys could give me some help? Greetings, Job Register_1.php: <?php include("dbcon.php"); include("functions.php"); $username = $_POST['username']; $password = $_POST['password']; if ( $username == "" || $password == "" ) { header("location:index.php?login=wr"); } else { if ( hasInvalidCharacters($username) ) { echo "Gebruikersnaam kan alleen letters bevatten [a-z A-Z]"; } else { $sql = " SELECT wachtwoord FROM timavnl_1.gebruikers WHERE gebruikersnaam = ? LIMIT 1; "; $sql2 = " SELECT approval FROM timavnl_1.gebruikers WHERE gebruikersnaam = ? LIMIT 1; "; $stmt = $mysqli->prepare($sql); $stmt->bind_param('s', $username); $stmt->execute(); $stmt->bind_result($hashedPw); $stmt->fetch(); if ( !crypt($password, $hashedPw) == $hashedPw ) { header("location:index.php?login=false"); } else { if ( $CheckedApp == 0 ) { header("location:index.php?login=nonapp") } else { echo "Inloggen is voltooid"; } } } } ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> <body> <h1> hoi </h1> </body> </html> Login_1.php: <?php include("dbcon.php"); include("functions.php"); $username = $_POST['username']; $password = $_POST['password']; if ( $username == "" || $password == "" ) { header("location:index.php?login=wr"); } else { if ( hasInvalidCharacters($username) ) { echo "Gebruikersnaam kan alleen letters bevatten [a-z A-Z]"; } else { $sql = " SELECT wachtwoord FROM timavnl_1.gebruikers WHERE gebruikersnaam = ? LIMIT 1; "; $sql2 = " SELECT approval FROM timavnl_1.gebruikers WHERE gebruikersnaam = ? LIMIT 1; "; $stmt = $mysqli->prepare($sql); $stmt->bind_param('s', $username); $stmt->execute(); $stmt->bind_result($hashedPw); $stmt->fetch(); if ( !crypt($password, $hashedPw) == $hashedPw ) { header("location:index.php?login=false"); } else { if ( $CheckedApp == 0 ) { header("location:index.php?login=nonapp") } else { echo "Inloggen is voltooid"; } } } } ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> <body> <h1> hoi </h1> </body> </html> Edited August 1, 2017 by Zeehamster Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 1, 2017 Share Posted August 1, 2017 And where is your code? Quote Link to comment Share on other sites More sharing options...
Zeehamster Posted August 1, 2017 Author Share Posted August 1, 2017 And where is your code? Editted the form. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 1, 2017 Share Posted August 1, 2017 ?? Guess you don't want help. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 1, 2017 Share Posted August 1, 2017 Now I see your code. So - what is the value of approval? Always the same? Check your logic. Try and be a little more informative instead of having us debug your entire script. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted August 1, 2017 Share Posted August 1, 2017 It looks like you are retrieving the "approval" column in a separate query assigned to $sql2. Are you executing the query somewhere? Also, is there a reason for using two separate queries? You should be able to get both column values with: $sql = " SELECT wachtwoord, approval FROM timavnl_1.gebruikers WHERE gebruikersnaam = ? LIMIT 1; "; Quote Link to comment Share on other sites More sharing options...
Zeehamster Posted August 1, 2017 Author Share Posted August 1, 2017 It looks like you are retrieving the "approval" column in a separate query assigned to $sql2. Are you executing the query somewhere? Also, is there a reason for using two separate queries? You should be able to get both column values with: $sql = " SELECT wachtwoord, approval FROM timavnl_1.gebruikers WHERE gebruikersnaam = ? LIMIT 1; "; Thnx, editted it. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted August 1, 2017 Share Posted August 1, 2017 Thnx, editted it. No problem. Does this mean the script is working? If not, did you adjust the code to use the "approval" column? Quote Link to comment Share on other sites More sharing options...
Zeehamster Posted August 1, 2017 Author Share Posted August 1, 2017 Now I see your code. So - what is the value of approval? Always the same? Check your logic. Try and be a little more informative instead of having us debug your entire script. <?php include("dbcon.php"); include("functions.php"); $username = $_POST['username']; $password = $_POST['password']; if ( $username == "" || $password == "" ) { header("location:index.php?login=wr"); } else { if ( hasInvalidCharacters($username) ) { echo "Gebruikersnaam kan alleen letters bevatten [a-z A-Z]"; } else { $sql = " SELECT wachtwoord, approval FROM timavnl_1.gebruikers WHERE gebruikersnaam = ? LIMIT 1; "; //PASSWORD CHECK $stmt = $mysqli->prepare($sql); $stmt->bind_param('s', $username); $stmt->execute(); $stmt->bind_result($hashedPw); //CHECK IF USER HAS CORRECT PASSWORD AND APPROVAL //APPROVAL NEEDS TO BE CHECKED WITH: $CheckedApp $stmt->fetch(); //PASSWORD CHECK + APPROVAL CHECK if ( !crypt($password, $hashedPw) == $hashedPw ) { header("location:index.php?login=false"); } else { //CORRECT = LOGGED IN echo"password = correct | Logged in"; } } } } ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> <body> <h1> hoi </h1> </body> </html> i want the password & approval check in the if statement and when password is correct and approval = 1 in database the user can log in Quote Link to comment Share on other sites More sharing options...
Zeehamster Posted August 1, 2017 Author Share Posted August 1, 2017 No problem. Does this mean the script is working? If not, did you adjust the code to use the "approval" column? The script is already working I wanna build a Admin Approval check in the if statement (see code in comments) Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted August 1, 2017 Share Posted August 1, 2017 The script is already working Sorry, wrong choice of words. I was just wondering if the problem is solved. I wanna build a Admin Approval check in the if statement (see code in comments) The query should now return the value of the "approval" column. You just need to modify the code to use it. Basically, you need to modify the call to bind_result() and adjust your if tests at the bottom to verify the "approval" column value. Quote Link to comment Share on other sites More sharing options...
benanamen Posted August 1, 2017 Share Posted August 1, 2017 Additionally, there is no need for LIMIT 1. The username is unique (it should be), therefore you are only going to get one result already. Quote Link to comment Share on other sites More sharing options...
Zeehamster Posted August 1, 2017 Author Share Posted August 1, 2017 Additionally, there is no need for LIMIT 1. The username is unique (it should be), therefore you are only going to get one result already. Thanks, Can't find how to checks if the approval = 1 of the user. Current code: $stmt = $mysqli->prepare($sql); $stmt->bind_param('ss', $username, $approval); $stmt->execute(); $stmt->bind_result($hashedPw, $CheckedApp); //CHECK IF USER HAS CORRECT PASSWORD AND APPROVAL //APPROVAL NEEDS TO BE CHECKED WITH: $CheckedApp $stmt->fetch(); //PASSWORD CHECK + APPROVAL CHECK if ( crypt($password, $hashedPw) == $hashedPw && $CheckedApp == 1 ) { echo"password = correct | Logged in"; } else { //INCORRECT - Log OFF header("location:index.php?login=false"); } } } Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted August 1, 2017 Share Posted August 1, 2017 Can't find how to checks if the approval = 1 of the user. Does $CheckedApp contain what you expect? You could use PHP var_dump() function to find out. Also note that I don't know what your database looks like. Does your database table (timavnl_1.gebruikers) contain a column named "approval"? Does that column contain the values you expect? Quote Link to comment Share on other sites More sharing options...
Zeehamster Posted August 1, 2017 Author Share Posted August 1, 2017 Does $CheckedApp contain what you expect? You could use PHP var_dump() function to find out. The $CheckedApp is containing: NULL Also note that I don't know what your database looks like. Does your database table (timavnl_1.gebruikers) contain a column named "approval"? Does that column contain the values you expect? Yes $sql = " SELECT wachtwoord, approval FROM timavnl_1.gebruikers WHERE gebruikersnaam = ? "; 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.