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
https://forums.phpfreaks.com/topic/242497-can-anyone-help-me-with-this-basic-code/
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

  Quote

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);
{

}

 

 

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.