Jump to content

Notice: Undefined index! (PHP ERROR)


TottoBennington

Recommended Posts

Notice: Undefined index: username in C:\wamp\www\LogInSystem\login.php on line 2

Notice: Undefined index: password in C:\wamp\www\LogInSystem\login.php on line 3

 

Help me to change this error

 

<?php
$username = $_POST['username'];     ERROR IS IN THIS LINE
$password = $_POST['password'];      ERROR IS IN THIS LINE

if ($username&&$password){

$connect = mysql_connect ("localhost", "root","") or die ("could not connect");

mysql_select_db ("login") or die ("could not find db");

} else { die ("Please enter username and password!");}
?>

Link to comment
Share on other sites

holy big text batman..

 

you are receiving these "notices" (they aren't errors) because you are attempting to call on $_POST values that do not exist upon page load.

 

if(isset($_POST['username']) && isset($_POST['password'])) {
    $username = $_POST['username'];
    $password = $_POST['password'];
}

Link to comment
Share on other sites

  • 3 months later...

Please help me I have exhausted now to find out the solution for this. I am new and learning php.

 

I am facing this error.

 

 

( ! ) Notice: Undefined index: password in C:\wamp\www\login.php on line 7

Call Stack

# Time Memory Function Location

1 0.0015 374152 {main}( ) ..\login.php:0

Please enter the username and password

 

...............................................................

 

My Form code is......

 

 

<html>

 

 

<form action="login.php" method="POST">

<p><input type="text" name="username"></p>

<p><input type="password" name="passsword"></p>

<p><input type="submit" name="submit" value="login"></p>

</form>

 

 

 

</html>

 

 

and my login.php code is.....

 

<?php

 

 

session_start();

 

$username=$_POST['username'];

$password=$_POST['password'];

 

 

if ($username&&$password)

{

 

$connect = mysql_connect('localhost','root','') or die ("Couldn't connect to database");

mysql_select_db("alaqsatr_2374") or die ("Couldn't find database");

 

$query = mysql_query("SELECT * FROM users WHERE username='$username'");

 

$numrows = mysql_num_rows($query);

 

if($numrows !=0)

 

{

 

while ($row = mysql_fetch_assoc($query))

{

 

$dbusername = $row['username'];

$dbpassword = $row['password'];

 

}

if  ($username==$dbusername&&$password==$dbpassword)

{

 

echo "Login successful. <a href='membersarea.php'> Click here to enter the members area";

$_SESSION['username']=$dbusername;

 

}

 

else

echo "Incorrect password";

 

}

 

else

die("That username doesn't exist.");

}

 

else

die("Please enter the username and password");

 

 

 

 

?>

 

Please reply me my email is mwaleedgul@yahoo.com . many thanks

Link to comment
Share on other sites

  • 3 weeks later...

Hello

 

Your problem looks to be on your form.

 

You have named the field "passsword" - note the incorrect spelling of password (you have added three S's).

 

The php script is then looking for 'password' - with the correct spelling. This is why you are getting undefined index. Your form is posting "passsword" but your php script is looking for "password" in the post array.

 

Hope that fixes it!

 

Drongo

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.