Login form - Viewing Errors!
Posted: Thu Mar 15, 2012 5:27 pm
This is my code :
Thank you!
<body> <?php include 'config.php' ; if (isset($_POST['username'], $_POST['password'])) { $username = $_POST['username'] ; $password = md5($_POST['password']) ; $errors = array() ; if (empty ($username) && empty ($password) ) { $errors[] = 'Please enter your username and password'; } else if (empty ($username)) { $errors[] = 'Please enter your username'; } else if (empty($password)) { $errors[] = 'Please enter your password' ; } else { $login_check = mysql_query("SELECT `id` FROM `users` WHERE `username`='$username' AND `password`='$password'"); $rows = mysql_num_rows ($login_check); if ($rows == 0) { $errors[] = 'Incorrect username/password' ; } else if ($rows == 1) { $_SESSION['user_id'] = $user_id; header('Location: profile.php'); exit() ; } } /* else if (!empty ($errors)) { foreach ($errors as $error) { echo $error ; */ /* I want this to be below in the div tag. If I put it in the div, it won't work. I need to place it where it'll work! */ } } ?> <!--The whole body is wrapped in 'whole_body_wrapper'--> <div id="whole_body_wrapper"> <!--Header with login form and title--> <div id="main_header"> <h1>Budzzem</h1> <!--Login form--> <div id="login_form"> <div id="phpErrors" style="color:#F00"><?php //HERE ?></div> <form action="" method="POST"> <input type="text" class="login_inputs" placeholder="Username" name="username" /> <input type="password" value="" class="login_inputs" placeholder="Password" name="password"/> <input type="submit" value="Sign In" class="login_inputs" id="signInBtn" /> </form> </div> </div>I don't know where to place the foreach loop! I want the errors to be viewed in the div tag where 'HERE' is commented!
Thank you!