Jump to content

[Error]Undefined Index In Login System


Diether

Recommended Posts

Hi guys, can someone help me to solve my problem in creating a login system? :( thanks in advance

 

 

i get this error

Notice: Undefined index: txtUsername in C:\xampp\htdocs\online\storeAdmin\admin_login.php on line 6

Notice: Undefined index: txtPassword in C:\xampp\htdocs\online\storeAdmin\admin_login.php on line 7

 

This are the two lines :

$userName = $_POST['txtUsername'];

$password = $_POST['txtPassword'];

 

The code i use:

function doLogin()
{
   // if we found an error save the error message in this variable
   $errorMessage = '';
   $userName = $_POST['txtUsername'];
   $password = $_POST['txtPassword'];

   // first, make sure the username & password are not empty
   if ($userName == '') {
    $errorMessage = 'You must enter your username';
   } else if ($password == '') {
    $errorMessage = 'You must enter the password';
   } else {
    // check the database and see if the username and password combo do match
    $sql = "SELECT user_id
		    FROM tbl_user
		    WHERE user_name = '$userName' AND user_password = PASSWORD('$password')";
    $result = dbQuery($sql);

    if (dbNumRows($result) == 1) {
	    $row = dbFetchAssoc($result);
	    $_SESSION['plaincart_user_id'] = $row['user_id'];

	    // log the time when the user last login
	    $sql = "UPDATE tbl_user
			    SET user_last_login = NOW()
			    WHERE user_id = '{$row['user_id']}'";
	    dbQuery($sql);
	    // now that the user is verified we move on to the next page
	    // if the user had been in the admin pages before we move to
	    // the last page visited
	    if (isset($_SESSION['login_return_url'])) {
		    header('Location: ' . $_SESSION['login_return_url']);
		    exit;
	    } else {
		    header('Location: index.php');
		    exit;
	    }
    } else {
	    $errorMessage = 'Wrong username or password';
    }	   

   }

   return $errorMessage;
}
<html>
  <form id="form1" name="form1" method="post" action="admin_login.php">
	    <p align="center">username:<input type="text" name="txtUsername" id="username" />
	    </p>
	    <p align="center">password:<input type="password" name="txtPassword" id="password" />
	    </p>
	    <p align="center"> </p>
	  </blockquote>
	  <p align="center">
	    <input type="submit" name="log_in" id="log_in" value="Log in" />
	  </p>
    </form>

Link to comment
Share on other sites

Basically your _POST data does not exist. This script is looking for "txtUsername" in the $_POST array and it isn't there. Are you using the right input name from HTML? Has the form been submitted when this script is ran?

Edited by doddsey_65
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.