www Posted April 3, 2011 Share Posted April 3, 2011 I'm writing a very simple clean login session as a demonstration to friends. I've been over this code a lot of times and can't fault it, but obviously I am wrong.. or maybe xampp is just having one of those days. Undefined Index: username on line 30, login.php all files involved are attached. Thanks in advance. <?php session_start(); $username = $_POST['username']; $password = $_POST['password']; if ($username&&$password) { $connect = mysql_connect("localhost","root","") or die("couldn't connect"); mysql_select_db("login") or die("couldn't find db"); $query = mysql_query("SELECT * FROM users WHERE username='$username'"); $numrows = mysql_num_rows($query); if ($numrows!=0) { //login code while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } //check is pass & user match if ($username==$dbusername&&$password==$dbpassword) { echo "you're in click here to enter the <a href='member.php'>member page</a> haha"; $_SESSION['username']==$dbusername; } else echo "incorrect password"; } else die("that user doesn't exist"); } else die("failed to connect") ?> [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/232558-undefined-index-im-going-insane/ Share on other sites More sharing options...
requinix Posted April 3, 2011 Share Posted April 3, 2011 Walk away from your computer for a bit. Make a sandwich. Watch TV. Do something that will distract you. Then come back and look at line 30 carefully. There's a typo. Quote Link to comment https://forums.phpfreaks.com/topic/232558-undefined-index-im-going-insane/#findComment-1196196 Share on other sites More sharing options...
spiderwell Posted April 3, 2011 Share Posted April 3, 2011 you have put == instead of = in line 30 so its looking to compare a session variable that doesnt exist yet Quote Link to comment https://forums.phpfreaks.com/topic/232558-undefined-index-im-going-insane/#findComment-1196197 Share on other sites More sharing options...
www Posted April 3, 2011 Author Share Posted April 3, 2011 Walk away from your computer for a bit. Make a sandwich. Watch TV. Do something that will distract you. Then come back and look at line 30 carefully. There's a typo. Perfect advice. After the 10hour haul I only needed a little break before I came back, looked at the code and felt incredibly embarrassed and pressed a single backspace haha. Thanks requinix. you have put == instead of = in line 30 so its looking to compare a session variable that doesnt exist yet Thanks spiderwell. Fatigue is killing my brain haha. Quote Link to comment https://forums.phpfreaks.com/topic/232558-undefined-index-im-going-insane/#findComment-1196201 Share on other sites More sharing options...
spiderwell Posted April 3, 2011 Share Posted April 3, 2011 yeah the other guy posted during the time i responded, and i wish i had left alone, it was the better response. and dont feel bad, i have done exactly the same kind of thing and then spent hours not spotting it!! Quote Link to comment https://forums.phpfreaks.com/topic/232558-undefined-index-im-going-insane/#findComment-1196205 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.