Nikk Posted August 4, 2010 Share Posted August 4, 2010 Hey guys, I've been coding PHP for about two weeks now, so excuse the appalling code. Here is the error message Notice: Undefined variable: dbusername in C:\wamp\www\twitbiscuit\process.php on line 25 Here is a pastie link to my code, thanks in advance. http://pastie.org/1076001 ( The fact my first post is asking for help, fail. ) Quote Link to comment Share on other sites More sharing options...
hcdarkmage Posted August 4, 2010 Share Posted August 4, 2010 $row = mysql_fetch_assoc($query); $dbusername = $row['username']; $dbpassword = $row['password']; should be: while($row = mysql_fetch_assoc($query)){; $dbusername = $row['username']; $dbpassword = $row['password']; } Quote Link to comment Share on other sites More sharing options...
marcus Posted August 4, 2010 Share Posted August 4, 2010 From your code it's telling me that either username or password isn't defined, thus dbusername is never defined in the process. @hcdarkmage, he's doing a login, not looping through the database. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted August 4, 2010 Share Posted August 4, 2010 A notice is nothing realy to worry about but ideally you'd want to strive to eliminate them. All it means is that you're accessing something [variable] that hasn't yet been set. In your case one or more of those variables are being referenced without being defined. Quote Link to comment Share on other sites More sharing options...
hcdarkmage Posted August 4, 2010 Share Posted August 4, 2010 Sorry, mgallforever, still half dead. Long day at work and I wasn't paying attention very well. As for the problem at hand you may want to put your if ($username==$dbusername&&$password==$dbpassword) statement into the if ($username&&$password) statement: //setting the first variables $username = $_POST['username']; $password = $_POST['password']; if ($username&&$password) { // connecting $connect = mysql_connect("localhost","root","") or die ("couldn't connect"); mysql_select_db("phplogin") or die ("no sign of db"); $query = mysql_query("SELECT * FROM users WHERE username='$username'"); $numrows = mysql_num_rows($query); $row = mysql_fetch_assoc($query); $dbusername = $row['username']; $dbpassword = $row['password']; // check to see if they match! if ($username==$dbusername&&$password==$dbpassword) echo "logged in! <a href='member.php'>Click</a> view your live feed"; else echo "Login failed, check username and password"; } 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.