Jump to content

Login script not working :(


dennismonsewicz

Recommended Posts

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

<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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.