undefined index username

Problems with the Windows version of XAMPP, questions, comments, and anything related.

undefined index username

Postby apolakay » 16. October 2011 12:47

Hi everyone
I'm new for php i watch tutorial user login and log out and i just follow the code but when i try it i have an error like this:Notice: Undefined index: username in C:\xampp\htdocs\xampp\member.php on line 5
and this is my code for login
<?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("phplogin") or die ("Couldn't find DB");
$query = mysql_query("SELECT * FROM users WHERE username = '$username'");
$numrows = mysql_numrows($query);
if ($numrows!=0)
{
while ($row = mysql_fetch_assoc($query))
{
$dbusername = $row['username'];
$dbpassword = $row['password'];
}
if ($username==$dbusername&&$password==$dbpassword)
{
echo "your login <a href='member.php'>Click</a> here to enter the member page.";
$_SESSION['username']==$dbusername;
}
else
echo "Incorrect password";
}
else
die("That user doesn't exist");

}
else
die("Please enter a username or Password");

?>

and other code for membership.php
<?php

session_start();

echo "Welcome, ".$_SESSION['username']."!<br><a href='logout.php'>Logout</a>"; <== THIS IS MY ERROR


?>
apolakay
 
Posts: 3
Joined: 16. October 2011 12:40

Re: undefined index username

Postby Altrea » 16. October 2011 12:59

Hi apolakay,

before we can help you we need some information about your XAMPP Version (if XAMPP is used) and your Operating System.

P.S.: Your PHP error doesn't match on your information. The error is referencing to member.php, your code where you think the error is is named by you membership.php. What is the truth?
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: undefined index username

Postby apolakay » 16. October 2011 13:05

Hi
I used XAMPP Version is 1.7.4 and my Operating system is Windows 7.sorry for the wrong information i used for member.php.
apolakay
 
Posts: 3
Joined: 16. October 2011 12:40

Re: undefined index username

Postby Altrea » 16. October 2011 13:12

Windows 7 Home Premium / Professional / Ultimate? 32Bit or 64Bit? Be as specific as possible please.
Do you use the new XAMPP control panel v3 or the standard one delivered with XAMPP 1.7.4?
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: undefined index username

Postby apolakay » 16. October 2011 13:31

I used window 7 Ultimate 32 bit. and i used XAMPP control panel vesion 2.5
apolakay
 
Posts: 3
Joined: 16. October 2011 12:40

Re: undefined index username

Postby Altrea » 16. October 2011 13:47

Okay, the good news first:

Your notice don't have any effect on the functionality of your code.
Thats just a message from your PHP Parser that you want to use a variable (or in your case a index of an array) which isn't set at the moment.

In your code thats the point, if you haven't sended your register form.

You could redefine the error_reporting of your PHP to hide this messages, or you could tweak your code a little bit to get rid of them (which i wouldn't recommend if you want to follow a tutorial).
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: undefined index username

Postby Nobbie » 17. October 2011 08:37

>$_SESSION['username']==$dbusername;

That is simply wrong, as it is a boolean expression (a comparison), and not an assignment!

You must use '=' instead of '=='.
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 115 guests