I'm trying to make it so a cookie saves the users name and then puts it in the HTML placeholder next time they visit. What's the most efficient way of doing this?

I searched the other threads and tried using 'include' and putting $name in the input placeholder, but it ends up giving me errors because txtName and txtAge are undefined. I'm unsure how to reorganize my code to get it working.

PHP&HTML Doc#1:

```
    $doc = "<!DOCTYPE html>
        <html lang='en'>
        SOME HTML........
        <input type='text' name='txtName' id='txtName' placeholder='$name'>
        SOME HTML........
    </html>";

echo $doc;

```

PHP/Doc#2:

```
<?php 

    $name = $_POST["txtName"];
    $age = $_POST["txtAge"];
    $k = $_POST['radRaceLength'];

    ///check if cookie exists
    if ( isset($_COOKIE["nameData"]) ){
        $name = $_COOKIE["nameData"];
    }
    else{
        $name = $name;
    }
    if ( isset($_COOKIE["ageData"]) ){
        $age = $_COOKIE["ageData"];
    }
    else{
        $age = $age;
    }
    setcookie("nameData", $name, time() + 3600, "/");
    setcookie("ageData", $age, time() + 3600, "/");

    $fiveK = 10 + ($age / 2); 
    $tenK = 18 + ($age / 3);
    $member = isset($_POST["chkMember"]) ? $fiveK = $fiveK - 5 AND $tenK = $tenK - 5: $member = NULL;

    if ( !$name AND $age <= 21 )
        echo "Please provide a name and valid age";
    else

        echo $name.', you are registered for the '.$k.' race. Your fee is: ';
        echo ( ($_POST["radRaceLength"] == "5K")? "$fiveK":"$tenK" );

?>

```