Jump to content

Recommended Posts

<?php

$user_name = 'bazarr';
$user_password = '*******';


if($_POST['user_name'] != $user_name || $_POST['user_password'] != $user_password) {

?>

<h3>The Login</h3>
<form method="post" action="">
    <input type="text" name="user_name" />
    <input type="password" name="user_password" />
    <input type="submit" name="blog_creation_login_submit" value="Submit" />
</form>

<?php
} else {
?>




<h3>The Article</h3>

 

With the above script I am getting following notice:

 

Notice: Undefined index: user_name

 

It is regarding the user name variable, my question is how to solve this one and avoid the notice?

You avoid the notice by checking to see if the variable exists. 

 

Index, in this context, means array index.  The array in question is $_POST.  It's telling you that $_POST['user_name'] doesn't exist; or, more specifically, 'user_name' is an undefined index because it wasn't set during the POST because whatever form input it's supposed to come from was empty.

 

So, you need to ensure that the variable exists by checking either isset or empty before attempting to use it in another way.

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.