[Solved] Notice: Undifined variable: [value] [duplicate]

Introduction

This question is related to a common issue encountered when programming in PHP. The error message “Notice: Undefined variable: [value]” indicates that a variable has been used in the code without being declared or assigned a value. This can lead to unexpected results and can be difficult to debug. In this post, we will discuss how to solve this issue and provide some tips for avoiding it in the future.

Solution

The most likely cause of this error is that the variable has not been declared or initialized. To fix this, you need to declare the variable and assign it a value. For example:

int value = 0;

You do not check if the following variables are set before you assign them.

$_POST['naam']
$_POST['wacht']

As you did with $_POST['login'] you can use isset to check they exist before assignment.

if (isset($_POST['naam'] && isset($_POST['wacht']) {
    // Do something...
}

In addition to this in the query you are using the variables $gebruikersnaam and $wachtwoord which you don’t appear to be referencing anywhere else? So after some google translating I’m guessing that you intended for this bit of code:

$username =mysql_real_escape_string( $_POST['naam']);
$password =md5( $_POST['wacht']);

To be the following:

$gebruikersnaam = mysql_real_escape_string($_POST['naam']);
$wachtwoord     = md5($_POST['wacht']);

Hopefully that helps, just a bit of a side note though, I would really advise reading over http://www.phptherightway.com/ and getting familiar with some of the best practices for PHP.

In your code I would attempt to refactor it and utilise password_hash() and mysqli_* as MD5() is not secure and the mysql_ extension has been removed in the latest version of PHP and was deprecated before that.

2

solved Notice: Undifined variable: [value] [duplicate]

If you are getting an error message that says “Notice: Undefined variable: [value]”, it means that you are trying to use a variable that has not been defined. This could be because you have not declared the variable, or because the variable has been declared but not assigned a value. To fix this issue, you need to either declare the variable and assign it a value, or make sure that the variable has been assigned a value before you try to use it.

For example, if you are trying to use a variable called $myVar but it has not been declared, you would need to declare it first:

$myVar = "some value";

Once you have declared the variable and assigned it a value, you can then use it in your code. If the variable has already been declared but not assigned a value, you will need to assign it a value before you can use it.

It is important to remember that variables must be declared and assigned a value before they can be used. If you are getting an error message that says “Notice: Undefined variable: [value]”, it means that you need to either declare the variable and assign it a value, or make sure that the variable has been assigned a value before you try to use it.