Jump to content

PHP login error


nitation

Recommended Posts

I have a login script that works fine. I decided to add this line of code

error_reporting(E_ALL);
ini_set('display_errors', 'on');

to my script. I keep getting this error

 

Notice: Undefined index: admin_user in C:\Program Files\xampp\htdocs\myfiles\vest\newnd\admin\login.php on line 14

Notice: Undefined index: admin_pass in C:\Program Files\xampp\htdocs\myfiles\vest\newnd\admin\login.php on line 15

Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\xampp\htdocs\myfiles\vest\newnd\admin\login.php:14) in C:\Program Files\xampp\htdocs\myfiles\vest\newnd\admin\login.php on line 37

 

This is my login script

 

<?php
error_reporting(E_ALL);
ini_set('display_errors', 'on');
session_start();

if (!isset ($_SESSION["admin_user"]))

{
  header ("Location:main.php?login=missing");
}
include 'connect.php';

// username and password sent from form
$admin_user=$_POST['admin_user'];
$admin_pass=$_POST['admin_pass'];

// To protect MySQL injection (more detail about MySQL injection)
$admin_user = stripslashes($admin_user);
$admin_pass = stripslashes($admin_pass);
$admin_user = mysql_real_escape_string($admin_user);
$admin_pass = mysql_real_escape_string($admin_pass);

$sql="SELECT * FROM newndAdmin WHERE admin_user='$admin_user' and admin_pass='$admin_pass'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("admin_user");
session_register("admin_pass");
header("location:index.php");
}
else {
header("location:main.php?login=wrong");
//echo "Please check your username or password. If you still cant login your account has been disabled. Please contact an admin.";
}

?>

 

 

Link to comment
Share on other sites

Notice: Undefined index: admin_user in C:\Program Files\xampp\htdocs\myfiles\vest\newnd\admin\login.php on line 14

Notice: Undefined index: admin_pass in C:\Program Files\xampp\htdocs\myfiles\vest\newnd\admin\login.php on line 15

 

$admin_user and $admin_pass are empty.

Link to comment
Share on other sites

the warnings mean that the $_POST[] array contains no keys called admin_user and admin_pass.

this means that fields you think are called these names are actually called something else (or maybe don't exist?). i see that earlier in your code you use $_SESSION['admin_user']. is it possible that you should be using $_SESSION on lines 14,15 instead of $_POST?

Link to comment
Share on other sites

the warnings mean that the $_POST[] array contains no keys called admin_user and admin_pass.

this means that fields you think are called these names are actually called something else (or maybe don't exist?). i see that earlier in your code you use $_SESSION['admin_user']. is it possible that you should be using $_SESSION on lines 14,15 instead of $_POST?

I created the form myself. The input name is the same variable i used in the login page.

Link to comment
Share on other sites

you mean reloading the form and having "Wrong Password" appear in intimidating bold red letters next to the password field? i would just post the form to itself, and move the login script to the top of the file with:

 

<?php
$passwordValid = TRUE;
if (isset($_POST['submit']){ //submit being the name of the submit button
     if (//find out if password is wrong){
         $passwordValid = FALSE; //password is wrong, don't allow entry! skip login code
     }
    else{
    //more login.php code for valid passwords
    }
}
?>
<html>
html code
<input type="password" ..... /> <?php echo ($passwordValid?"":"beware! your password is wrong! muahahahah!"); ?>

 

i'd still like to see the var_dump($_POST); in login.php. maybe even var_dump($_POST, $_SESSION); too cover everything.

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.