Jump to content

Php Simple Log In Videos Tutorials


SteveNI

Recommended Posts

I wonder if someone can help me.

I am following Bens tutorials on building a simple log in system.

I am on the third video and so far I believe I've followed it line by line.

At point 5.30 seconds he refreshes the login page and all the previous errors he had all disappeared, however when I enter the same code I still have the error Notice: undefined variable: error in ...v_login.php on line 18

 

Like I said I was sure I had followed Ben to the letter, I cannot see where $error is defined in the v_login script, however it seems to work in Bens code.

 

What could I be doing wrong?

Link to comment
Share on other sites

Here is my code, I'm taking things a little bit further than you and see this as a registration of a user where we take name, username, password, email etc from the user. Though I should imagine this is the same principle as what you are doing.

Here is my v_login

<html>
   <head>
       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
       <title>Registration</title>
       <link href="style.css" media="screen" rel="stylesheet" type="text/css"/>
   </head>
   <body>
       <h1>Register</h1>
       <div id="content">
           <form action="" method="post">
               <div>

                   <?php if($error['alert']!='')
                   echo "<div class='alert'>".$error['alert']."</div>"?>

                   <label for="firstname">First Name: * </label>
                   <input type="text" name="firstname" value="<?php echo $input['first'];?>">
                   <div class ="error"><?php echo $error['first'];?></div>
                   <label for="lastname">Second Name: * </label>
                   <input type="text" name="lastname" value="<?php echo $input['last'];?>">
                   <div class ="error"><?php echo $error['last'];?></div>
                   <label for="username">Username: * </label>
                   <input type="text" name="username" value="<?php echo $input['user'];?>">
                   <div class ="error"><?php echo $error['user'];?></div>
                   <label for="password">Password: * </label>
                   <input type="text" name="password" value="<?php echo $input['pass'];?>">
                   <div class ="error"><?php echo $error['pass'];?></div>
                   <label for="password2">Re-Confirm Password: * </label>
                   <input type="text" name="password2" value="<?php echo $input['pass2'];?>">
                   <div class ="error"><?php echo $error['pass2'];?></div>
                   <label for="email">Email: * </label>
                   <input type="text" name="email" value="<?php echo $input['em'];?>">
                   <div class ="error"><?php echo $error['em'];?></div>
                   <p class="required">Required Fields</p>

                   <input type="submit" name="submit" class="submit" value="Submit">
               </div>    
           </form>
       </div>
       <?php

       ?>
   </body>
</html>

 

Then I have started to create my login.php script as you did, I have echoed what you have done creating input and error variables, though obviously I have more as i have more fields. This is as far as I have got in your tutorial and when you test the code all your errors have disappeared

<?php

//Start session
session_start();
include('config.php');
include('connect-To-db.php');

include('v_login.php');

$error ['alert'] = '';
$error ['first'] = '';
$error ['last'] = '';
$error ['user'] = '';
$error ['pass'] = '';
$error ['pass2'] = '';
$error ['em'] = '';
$input ['first'] = '';
$input ['last'] = '';
$input ['user'] = '';
$input ['pass'] = '';
$input ['pass2'] = '';
$input ['em'] = '';


?>

Link to comment
Share on other sites

I believe the issue here is the order of your code. within login.php, see how the include() line is before the definition of the $input and $error variables? This means that the view is being loaded too early, and those variables don't exist yet. I believe if you move your include line later within the login.php file, after you define your $errors and $inputs.

 

Hope that helps?

Link to comment
Share on other sites

I believe the issue here is the order of your code. within login.php, see how the include() line is before the definition of the $input and $error variables? This means that the view is being loaded too early, and those variables don't exist yet. I believe if you move your include line later within the login.php file, after you define your $errors and $inputs.

 

Hope that helps?

I have moved the include line below my variables in login.php but I am still getting the Notice: undefined variable: error in ...v_login.php on line 18

Its very frustrating lol!

Link to comment
Share on other sites

When I test using:

 

<?php

//Start session
session_start();
include('config.php');
include('connect-To-db.php');

$error ['alert'] = '';
$error ['first'] = '';
$error ['last'] = '';
$error ['user'] = '';
$error ['pass'] = '';
$error ['pass2'] = '';
$error ['em'] = '';
$input ['first'] = '';
$input ['last'] = '';
$input ['user'] = '';
$input ['pass'] = '';
$input ['pass2'] = '';
$input ['em'] = '';

include('view.php');

?>

I don't get any errors. If you want, however, send your files and a dump of your database to ben [at] falkencreative.com, and I'll see if there is something else going on?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...