rnintulsa Posted July 25, 2008 Share Posted July 25, 2008 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. Link to comment https://forums.phpfreaks.com/topic/116619-solved-ugh-now-my-login-is-not-working-again/ Share on other sites More sharing options...
rnintulsa Posted July 25, 2008 Author Share Posted July 25, 2008 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> Link to comment https://forums.phpfreaks.com/topic/116619-solved-ugh-now-my-login-is-not-working-again/#findComment-599634 Share on other sites More sharing options...
Third_Degree Posted July 25, 2008 Share Posted July 25, 2008 You could try putting error_reporting(E_ALL); at the top of your script as well as adding or die(mysql_error()); to the end of all your mysql operations to see if you get any help with error messages. Link to comment https://forums.phpfreaks.com/topic/116619-solved-ugh-now-my-login-is-not-working-again/#findComment-599638 Share on other sites More sharing options...
rnintulsa Posted July 25, 2008 Author Share Posted July 25, 2008 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? Link to comment https://forums.phpfreaks.com/topic/116619-solved-ugh-now-my-login-is-not-working-again/#findComment-599640 Share on other sites More sharing options...
MFHJoe Posted July 25, 2008 Share Posted July 25, 2008 You sure $_POST['password'] has a value? Did you submit the form with no password? That could be causing it. Link to comment https://forums.phpfreaks.com/topic/116619-solved-ugh-now-my-login-is-not-working-again/#findComment-599652 Share on other sites More sharing options...
fanfavorite Posted July 25, 2008 Share Posted July 25, 2008 Watch the space in $_POST['password ']... should be $_POST['password'] Link to comment https://forums.phpfreaks.com/topic/116619-solved-ugh-now-my-login-is-not-working-again/#findComment-599653 Share on other sites More sharing options...
MFHJoe Posted July 25, 2008 Share Posted July 25, 2008 Watch the space in $_POST['password ']... should be $_POST['password'] Heh, well spotted. That'll be it. Link to comment https://forums.phpfreaks.com/topic/116619-solved-ugh-now-my-login-is-not-working-again/#findComment-599655 Share on other sites More sharing options...
rnintulsa Posted July 25, 2008 Author Share Posted July 25, 2008 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. Link to comment https://forums.phpfreaks.com/topic/116619-solved-ugh-now-my-login-is-not-working-again/#findComment-599662 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.