Search code examples
phphtmlspecialchars

Undefined index when calling htmlspecialchars


I'm getting the following error:

Notice: Undefined index: test

With reference to this line:

$token = htmlspecialchars($_GET["test"]);  

Do I need to define test somewhere even though I'm trying to read it from a URL?

-

-EDIT-

I had actually looked at the answer linked as a duplicate before posting this but couldn't see anything in it relating to using htmlspecialchars which I thought was causing the problem.


Solution

  • Your variable doesn't exists. Use isset to check this

    if(isset($_GET["test"]))
        $token = htmlspecialchars($_GET["test"]); 
    else
        echo "variable test doesn't exist";