wickedXxxxlegox Posted September 18, 2012 Share Posted September 18, 2012 'Ello everyone. I am having a problem with my login system. When I try to log in, it says login failed even though I have the correct username and pass. My username is Andrew Baker, and my pass is obviously a secret. Here's the code to checklogin.php: <?php // checkLogin.php require('includes/header.php'); session_start(); // Start a new session require('includes/db_connect.php'); // Holds all of our database connection information // Get the data passed from the form $username = $_POST['user']; $password = $_POST['password']; // Do some basic sanitizing $username = stripslashes($username); $password = stripslashes($password); $sql = "select * from members where username = '$username' and password = '$password'"; $result = mysql_query($sql) or die ( mysql_error() ); $count = 0; while ($line = mysql_fetch_assoc($result)) { $count++; } if ($count == 1) { $_SESSION['loggedIn'] = "true"; header("Location: home.php"); // This is wherever you want to redirect the user to } else { $_SESSION['loggedIn'] = "false"; header("Location: loginfailed.php"); // Wherever you want the user to go when they fail the login } ?> Thanks! If you need any more info then reply down here vvvvv Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 18, 2012 Share Posted September 18, 2012 Is the username in the database MORE than once? In addition: stripslashes is not sanitizing user input. You need to salt & hash the user's password. Quote Link to comment Share on other sites More sharing options...
wickedXxxxlegox Posted September 18, 2012 Author Share Posted September 18, 2012 No ma'm. There is only one user so far and that is me. Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 18, 2012 Share Posted September 18, 2012 Echo the query and run it in mysql or phpmyadmin. Is the query what you expect? Quote Link to comment Share on other sites More sharing options...
wickedXxxxlegox Posted September 18, 2012 Author Share Posted September 18, 2012 Well, now I have a problem with my code that is echoing it. <?php include('includes/db_connect.php'); mysql_query('SELECT * FROM members'); echo ("".srow['username'[); ?> Error: Parse error: syntax error, unexpected '[' in /home/a1922355/public_html/dbtest.php on line 6 Quote Link to comment Share on other sites More sharing options...
wickedXxxxlegox Posted September 18, 2012 Author Share Posted September 18, 2012 I'm only nine and I code o.0 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 18, 2012 Share Posted September 18, 2012 Read the error carefully, then read the line of code carefully. Quote Link to comment Share on other sites More sharing options...
wickedXxxxlegox Posted September 18, 2012 Author Share Posted September 18, 2012 There isn't an error. Stop treating people like crap. It makes me want to leave this site. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 18, 2012 Share Posted September 18, 2012 How can you possibly say there's no error when you are the one who posted the error to begin with? Here, let me quote it for you, from your very own post: Well, now I have a problem with my code that is echoing it. [sNIP] Error: Parse error: syntax error, unexpected '[' in /home/a1922355/public_html/dbtest.php on line 6 Oh, and trying to get you to read and understand your own code isn't "treating people like crap", it's trying to help you learn how to debug your own code, so you don't need to post every little syntax error you encounter. Quote Link to comment Share on other sites More sharing options...
acidpunk Posted September 18, 2012 Share Posted September 18, 2012 He isn't treating you like crap, he was just trying to get you to find you're own error, him telling you the exact problem isn't going to solve anything, you'll end up posting the same question next time. look at the error close, Error: Parse error: syntax error, unexpected '[' in /home/a1922355/public_html/dbtest.php on line 6 now, look at you're code. <?php include('includes/db_connect.php'); mysql_query('SELECT * FROM members'); echo ("".srow['username'[]); ?> basically, you're closing ['username'] like ['username'[ which is causing errors for you. Quote Link to comment Share on other sites More sharing options...
White_Lily Posted September 18, 2012 Share Posted September 18, 2012 I also know that "checklogin.php" is from a tutorial site as the code is also exactly the same, i also found unsolved problems with this tutorial code. Quote Link to comment Share on other sites More sharing options...
Monkuar Posted September 18, 2012 Share Posted September 18, 2012 There isn't an error. Stop treating people like crap. It makes me want to leave this site. LOL..... these guys are helping you voluntarily... sit back and take there advice with NO grain of salt, that is the only way to succeed, trust me, I know. sit back and enjoy the ride, trust me, they know what they're talking about 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.