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? Link to comment https://forums.phpfreaks.com/topic/96570-login-script-not-working/ 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? Link to comment https://forums.phpfreaks.com/topic/96570-login-script-not-working/#findComment-494214 Share on other sites More sharing options...
revraz Posted March 17, 2008 Share Posted March 17, 2008 Post the form Link to comment https://forums.phpfreaks.com/topic/96570-login-script-not-working/#findComment-494216 Share on other sites More sharing options...
dennismonsewicz Posted March 17, 2008 Author Share Posted March 17, 2008 same screen without a message Link to comment https://forums.phpfreaks.com/topic/96570-login-script-not-working/#findComment-494219 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> Link to comment https://forums.phpfreaks.com/topic/96570-login-script-not-working/#findComment-494221 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']; Link to comment https://forums.phpfreaks.com/topic/96570-login-script-not-working/#findComment-494226 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? Link to comment https://forums.phpfreaks.com/topic/96570-login-script-not-working/#findComment-494227 Share on other sites More sharing options...
revraz Posted March 17, 2008 Share Posted March 17, 2008 <?php session_start(); Link to comment https://forums.phpfreaks.com/topic/96570-login-script-not-working/#findComment-494241 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? Link to comment https://forums.phpfreaks.com/topic/96570-login-script-not-working/#findComment-494246 Share on other sites More sharing options...
dennismonsewicz Posted March 17, 2008 Author Share Posted March 17, 2008 TOPIC SOLVED! Link to comment https://forums.phpfreaks.com/topic/96570-login-script-not-working/#findComment-494252 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.