piano0011 Posted July 23, 2016 Share Posted July 23, 2016 Hey guys! Thanks for the wonderful forum! I am new to php programming and I am trying to do a login form by codecourse on youtube, perhaps it will help if I put the link here so someone could try to tell me where I have gone wrong...https://www.youtube.com/watch?v=AtivJV-kx5c For some reason, around the 4:40 minute mark in the tutorial, I am unable to get the username is required and password is required to be displayed on the screen when clicking on the submit button. Here is my code. I can't seem to find any errors. Thanks! <?php require_once 'core/init.php'; if(Input::exists()) { // check to see if input exists or not.... if(Token::check(Input::get('token'))) { // check that the token is correct and suppy by the form $validate = new Validate(); $validation = $validate->check($_POST, array( 'username' => array('required' => true), 'password' => array('required' => true) )); if($validation->passed()) { $user = new User(); // log user in.... make a new object so that we use the method $login = $user->login(Input::get('username'), Input::get('password')); if($login) { // check to see if login is successful or not echo 'Success'; } else{ echo '<p>Sorry, logging has failed!</p>'; } } else { foreach($validation->errors() as $error) { echo $error, '<br>'; } } } } ?> <form action="" method="POST"> <div class="field"> <label for="username">Username</label> <input type="text" name="username" id="username" autocomplete="off"> </div> <div class="field"> <label for="password">Password</label> <input type="password" name="password" id="password" autocomplete="off"> </div> <input type="hidden" name="token" value="<? php echo Token::generate(); ?>"> <input type="submit" value="Log in"> </form> <!-- To generate a token, use: <? php echo Token::generate(); ?> in the value="" section --> Quote Link to comment https://forums.phpfreaks.com/topic/301563-php-oop-login-system-not-working/ Share on other sites More sharing options...
Jacques1 Posted July 23, 2016 Share Posted July 23, 2016 (edited) So what does happen when you leave the fields empty? Are you getting an error? A blank page? Are you magically logged in? Be specific. Programming is an exact science, not a guessing game. Right now, all I can tell you is that a lot of your checks lack an else branch. If there are no POST parameters, or if the token is wrong, you keep quiet and don't give any feedback at all, which is obviously a problem. Edited July 23, 2016 by Jacques1 Quote Link to comment https://forums.phpfreaks.com/topic/301563-php-oop-login-system-not-working/#findComment-1534897 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.