Jump to content

undefined index.. I'm going insane


www

Recommended Posts

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]

Link to comment
https://forums.phpfreaks.com/topic/232558-undefined-index-im-going-insane/
Share on other sites

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.

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.