SteveNI Posted October 16, 2013 Report Posted October 16, 2013 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? Quote
falkencreative Posted October 16, 2013 Report Posted October 16, 2013 Are you following the OOP or non OOP version? Quote
SteveNI Posted October 17, 2013 Author Report Posted October 17, 2013 Hi Ben Its the non OOP one Its the Simple PHP Log in system, with 18 videos on it. Quote
falkencreative Posted October 17, 2013 Report Posted October 17, 2013 Can you post the file you are having trouble with, v_login.php I believe, and I can compare that against my code? Quote
SteveNI Posted October 17, 2013 Author Report Posted October 17, 2013 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'] = ''; ?> Quote
falkencreative Posted October 18, 2013 Report Posted October 18, 2013 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? Quote
SteveNI Posted October 20, 2013 Author Report Posted October 20, 2013 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! Quote
falkencreative Posted October 20, 2013 Report Posted October 20, 2013 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? Quote
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.
Note: Your post will require moderator approval before it will be visible.