Jump to content

piano0011

Members
  • Posts

    189
  • Joined

  • Last visited

Posts posted by piano0011

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