dennismonsewicz Posted March 17, 2008 Share Posted March 17, 2008 Here is my code: <?php if($_POST) { //If the form has been submitted $host = "localhost"; $db_username = "username"; $db_password = "password"; $db_name = "dbname"; mysql_connect("$host","$db_username","$db_password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannt select db"); $username = stripslashes($_POST['username']); $password = stripslashes($_POST['password']); $sql = "select * from db_table where username = '$username' and password = '$password'"; $result = mysql_query($sql); $count = mysql_num_rows($result); if($count == 1) { session_register("username"); session_register("password"); session_start(); header("location: " . SITE_URL . "?username=" . $username . ""); } else { echo '<div class="login"> <p>Wrong username and password!</p> <form action="index.php" method="post" name="loginform"> <input type="text" id="username" name="username" /> <input type="password" id="password" name="password" style="clear: right;" /> <input type="image" src="images/loginbutton.jpg" style="width: 66px; height: 33px; float: right; margin-right: 7px;" /> </form> <div class="loginfooter" style="clear: both;"> </div> </div>'; } } else { //Else, no post data. Form hasn't been submitted if($_SESSION) { //Is the user logged in? YES! echo '<div class="login"> <p>Welcome, ' . ucwords($_SESSION['username']) . '</p> <p style="text-align: left; padding-left: 10px;"><a href="includes/logout.php">Logout?</a></p> <p style="text-align: left; padding-left: 10px;">View Profile</p> <p style="text-align: left; padding-left: 10px;">My Photos</p> <div class="loginfooter" style="clear: both;"> </div> </div>'; } else { //User isn't logged in echo '<div class="login"> <p>Please Login to Utilize Your Account</p> <form action="index.php" method="post" name="loginform"> <input type="text" id="username" name="username" /> <input type="password" id="password" name="password" style="clear: right;" /> <input type="image" src="images/loginbutton.jpg" style="width: 66px; height: 33px; float: right; margin-right: 7px;" /> </form> <div class="loginfooter" style="clear: both;"> </div> </div>'; } } ?> The username is passed to the URL but does not display the Welcome, $username, the script just keeps reshowing the login form Any ideas? Quote Link to comment Share on other sites More sharing options...
lemmin Posted March 17, 2008 Share Posted March 17, 2008 Is it showing the "Wrong username and password!" or just the same screen without a message? Quote Link to comment Share on other sites More sharing options...
revraz Posted March 17, 2008 Share Posted March 17, 2008 Post the form Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted March 17, 2008 Author Share Posted March 17, 2008 same screen without a message Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted March 17, 2008 Author Share Posted March 17, 2008 <div class="login"> <p>Please Login to Utilize Your Account</p> <form action="index.php" method="post" name="loginform"> <input type="text" id="username" name="username" /> <input type="password" id="password" name="password" style="clear: right;" /> <input type="image" src="images/loginbutton.jpg" style="width: 66px; height: 33px; float: right; margin-right: 7px;" /> </form> <div class="loginfooter" style="clear: both;"> </div> </div> Quote Link to comment Share on other sites More sharing options...
revraz Posted March 17, 2008 Share Posted March 17, 2008 This is also wrong if($count == 1) { session_register("username"); session_register("password"); session_start(); You want session_start(); at the top and then use $_SESSION['username'] = $_POST['username']; Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted March 17, 2008 Author Share Posted March 17, 2008 When you say at the top where do you mean? Quote Link to comment Share on other sites More sharing options...
revraz Posted March 17, 2008 Share Posted March 17, 2008 <?php session_start(); Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted March 17, 2008 Author Share Posted March 17, 2008 Ok I did that but it is still doing the same thing. Any other ideas? Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted March 17, 2008 Author Share Posted March 17, 2008 TOPIC SOLVED! 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.