Jump to content

[SOLVED] Ugh! Now my login is not working again.


rnintulsa

Recommended Posts

I just got this login working yesterday with your help, and now I go to work on my site, and I can't log in.

Nothing has changed since it was working yesterday.

 

What could be wrong?

 

I am getting the :

"You must be registered before you may login" error.

 

My code:

<?php
session_start( );

// if username and password are set and not empty then proceed with the rest of the process
if( isset( $_POST[ 'username' ] ) && isset( $_POST[ 'password' ] ) && $_POST[ 'username' ] != '' && $_POST[ 'password' ] != '' )
{		
	$link = mysql_connect( 'host', 'username', 'password' );




	$db_selected = mysql_select_db('dbname', $link);

	$username = mysql_real_escape_string($_POST['username'], $link);
	$password = mysql_real_escape_string($_POST['password '], $link);

	if (!$db_selected) 
	{
		echo"Connection to the database failed. Please try again later." ;			
		exit;
	}

	//checks for username and password in db table.
	$results = mysql_query("select * from users where username='" . $username . "' and password = '" . $password . "'" ,$link);
	$num_rows = mysql_num_rows($results);

	//greater than zero		
	if( $num_rows  > 0 )
	{
		$_SESSION['username'] = $username;  
		//redirect
		header('Location:orion.php');  

	}
	else
	{
		echo 'You must be registered before you may log in.';
	}
}
?>

 

And this is my table:

create table users (
  id int not null auto_increment,
  username varchar( 50 ) not null,
  password varchar( 100 ) not null,
  company varchar( 10 ) not null default 'user', 
  primary key(id)
)

 

Why would it work fine yesterday, and not today?

 

I am a newbie, so please explain things out for me.

You are all greatly appreciated.

 

I forgot this is the login area:

<div id="center_column">

					<?php
						include( 'sessions.php' );
						show_statement( );

						if (isset($_SESSION['username'])) 
						{ 
							echo '<br />';
							echo 'Log '.$_SESSION['username'].'';		
							echo '<br /><a href="logout.php">Log out</a><br />';
						}
						else
						{
							echo 'Could not log you in<br />';
						}
					?>

					<form action="login.php" method="post">
						<p>
							Name:				
								<input type="text" name="username"/>
						</p>
						<p>
							Password:				
								<input type="password" name="password"/>
						</p>
						<p>
							<input type="submit" value="Log In"/>
						</p>


				</form>
				</div>	

 

Thanks Third_Degree. That helped.

 

 

Now I am getting this notice:

 

Notice: Undefined index: password in /nfs/cust/4/45/65/556544/web/login.php on line 18

You must be registered before you may log in.

 

 

 

And this is line 18:

$password = mysql_real_escape_string($_POST['password '], $link);

 

 

But my password is in the db and it is right. 

 

What could this mean?

 

Your right, great eye!! Have no idea how it got there either!

 

You guys are the best.

 

Another solved one.

 

I am getting ready to expand my knowledge and take this code a step further,

so I'll be in touch with questions.

 

Thanks a million.

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.