Search the Community
Showing results for tags 'remove form when used php'.
-
Hi guys - I've had problems with this for a couple of hours now, so now im asking you! ;-) I'm creating a blog, where i can log in in the header.php file (which i include on all the pages, as a sticky "move-around" -toolbar. But I would like the form to be removed when I am logged in, and instead have a log out button and preferences (or just to be removed as a start). I've tried to solve it by adding !$_session['user_id']{*FORM-CODE-WITH-INPUT-AREA-HERE}; meaning, that if the user is logged in, the above thing wont even come up. But i couldn't really make it work. Heres my code: <?php session_start(); if(isset($_POST['submit'])) { $user = $_POST['username']; $pwrd = $_POST['pwrd']; //include database connection include 'db_connect.php'; if(empty($user) || empty($pwrd)){ echo("Missing Information"); }else{ $user = strip_tags($user); $user = $db->real_escape_string($user); $pwrd = strip_tags($pwrd); $pwrd = $db->real_escape_string($pwrd); $pwrd = md5($pwrd); $query = $db->query("SELECT user_id, username FROM user WHERE username='$user' AND password='$pwrd'"); if($query->num_rows == 1){ while($row = $query->fetch_object()){ $_SESSION['user_id'] = $row->user_id; } header('Location: admin-page.php'); exit(); }else{ echo "Missing Information!"; } } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"/> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script src="http://code.jquery.com/jquery-1.5.min.js"></script> </head> <body> <div id="container"> <form action="login.php" method="post"> <p> <label>Username</label><input type="text" name="username"> <label>Password</label><input type="password" name="pwrd"> <input type="submit" name="submit" value="LogIn"> </p> </form> </div> </body> </html> And the code is by the way just the login.php, which i already included in the header.php.