Jump to content

Can anyone help me with this basic code???


N0L1m1t5

Recommended Posts

I am creating a login page for a web and i keep getting the error posted below:

 

 

Notice: Undefined index: username in C:\xampp\htdocs\login.php on line 26

 

Notice: Undefined index: password in C:\xampp\htdocs\login.php on line 27

Incorrect password

 

 

This is the code i have listed in my login.php document :

 

 

 

<?php

 

if( isset($_POST['submit']) && $_POST['Log in'])

 

session_start();

 

 

$username = $_POST ['username'];

$password = $_POST ['password'];

 

if ($username&&$password)

 

{

 

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

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

 

$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 "You're in!<a href='member.php'>Click here to enter the member page.</a>";

$_SESSION['username']=$username;

 

}

 

else

echo "Incorrect password";

 

}

else

die("That user doesn't exist!");

 

}

else

die("Please enter a username and a password!");

 

?>

 

 

 

 

 

 

Can anyone help me please??

Link to comment
Share on other sites

My first page only has the basic features so far: (posted below)

 

<html>

<body>

 

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

Username:   <input type='text' name = 'username'><br>

Password:          <input type = 'password' name = 'password'><br>

<input type = 'submit' value = 'Log in'>

 

</body>

</html>

 

 

 

 

But i keep getting that same error

Link to comment
Share on other sites

so what exactly does $row['username'] do and mean? is there a replacement code I could enter and test?

thanks

 

While a row of data exists, put that row in $row as an associative array. If you're expecting just one row, no need to use a loop which im guessing that there wont be more than 1 person with the same username.

 

 

try changing this

$numrows= mysql_num_rows($query);
if ($numrows!=0)
{
while($row = mysql_fetch_assoc($query))
{

$dbusername = $row['username'];
$dbpassword = $row['password'];
}

 

 

to this

 

 

$numrows= mysql_num_rows($query);
if ($numrows!=0)
{
$row = mysql_fetch_assoc($query);
print_r($row);
{

}

 

 

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.