jd2007 Posted July 15, 2007 Share Posted July 15, 2007 <?php /*Use of Sessions*/ if(!session_id()) session_start(); header("Cache-control: private"); //avoid an IE6 bug (keep this line on top of the page) if (isset($_POST["username"]) && isset($_POST["password"])) { /*Connection to database logindb using your login name and password*/ $db=mysql_connect('localhost','root') or die(mysql_error()); mysql_select_db('UserProfile'); $user_info = "SELECT * FROM users WHERE username='$user' AND password='$password'"; $result_name_check = mysql_query($user_info); $usersfound = mysql_num_rows($result_name_check); // if user not found, note that and end if ($usersfound < 1) { $error = "User $user not found."; // if user does exist, continue with processing } else { $_SESSION['Logged In'] = "true"; $_SESSION['username'] = $_POST['username']; $_SESSION['encryptpass'] = $user_info['cpass']; $_SESSION['email'] = $user_info['email']; $_SESSION['name'] = $user_info['name']; $_SESSION['age'] = $user_info['age']; $_SESSION['location'] = $user_info['location']; $_SESSION['personality'] = $user_info['personality']; $_SESSION['hobbies'] = $user_info['hobbies']; $_SESSION['email'] = $user_info['email']; $_SESSION['books'] = $user_info['books']; $_SESSION['shows'] = $user_info['shows']; $_SESSION['music'] = $user_info['music']; $_SESSION['occupation'] = $user_info['occupation']; $_SESSION['aboutme'] = $user_info['aboutme']; $_SESSION['photo'] = $user_info['photo']; echo "Welcome"; exit; } } else if (!isset($_POST["username"]) && isset($_POST["password"])) { echo "Please enter your username."; echo "<form method='post' action='login.php'> Username: <input type='text' name='username'><br> Password: <input type='text' name='password'><br> <input type='submit' value='Login'> </form>"; exit; } else if (isset($_POST["username"]) && !isset($_POST["password"])) { echo "Please enter your password."; echo "<form method='post' action='login.php'> Username: <input type='text' value=$_POST[username] name='username'><br> Password: <input type='text' name='password'><br> <input type='submit' value='Login'> </form>"; exit; } else if (!isset($_POST["username"]) && !isset($_POST["password"])) { echo "Please enter your username and password."; echo "<form method='post' action='login.php'> Username: <input type='text' name='username'><br> Password: <input type='text' name='password'><br> <input type='submit' value='Login'> </form>"; exit; } else {echo "Error";} ?> the login form is here: <?php /*Use of Sessions*/ if(!session_id()) session_start(); header("Cache-control: private"); //avoid an IE6 bug (keep this line on top of the page) echo "<form method='post' action='login.php'> Username: <input type='text' name='username'><br> Password: <input type='password' name='password'><br> <input type='submit' value='Login'> </form>"; ?> Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 15, 2007 Share Posted July 15, 2007 add to the end } else {echo "Error";} echo $error;//<<add to the end ?> EDIT: Also you have a SQL inject problem and over use the Sessions and $_SESSION['Logged In'] = "true"; should really be $_SESSION['Logged In'] = true; Quote Link to comment Share on other sites More sharing options...
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.