-5

Hello i'm new to php and i wanted to create a admin panel and i got an error with my register page.

This is the error :

Notice: Undefined index: username in C:\wamp\www\Website2 - Copy\register.php on line 18

if (isset($_POST['submit'])){   
    $username = $_POST['username']; // error here
    $password = md5($_POST['password']);
    if(empty($username)or empty($password)){
        echo"There is an empty space";
    }else{
        mysql_query("INSERT INTO users VALUES('', '$username', '$password')");
    }   
}
cmbuckley
  • 40,217
  • 9
  • 77
  • 91

1 Answers1

1

This happens because the empty function checks if the variables $username and $password has no value or set equal to zero. (0, null, false,''). As the empty function does not check if the variable exists, php throws this error.
In this case it would be correct to use the isset function of php.
http://br1.php.net/isset

Rafael Soufraz
  • 974
  • 3
  • 11
  • 28