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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.