I want the message below the input box to only show if that specific box's field is empty. If I put say "adam" in the name field, I get the following error:
Notice: Undefined variable: message2 in C:\xampp\htdocs\test\projects\Atom CMS\PHP\IF and POST lesson 2.php on line 28

please tell me what I'm missing!



<?php

if($_POST['sent'] == 1) {
if ($_POST['color'] == NULL) {
$message1 = 'please enter a color';
} else {
$mycolor = $_POST['color'];
}

if ($_POST['user'] == NULL) {
$message2 = 'please enter your name';
} else {
$myname = $_POST['user'];
}
}

?>
<style>
.welcomemessage{
color: <?php echo $mycolor ?>; /*dynamic css*/
}
</style>

<body>

<form action="IF and POST lesson 2.php" method="post">
<p>My name is: <input type="text" size="30" name="user" /></p>
<p><?php echo $message2; ?></p>
<p>My favorite color is: <input type="text" size="30" name="color" /></p>
<p><?php echo $message1; ?></p>
<input type="submit" value="login" />
<input type="hidden" value="1" name="sent" />
</form>

<?php

if ($_POST['user'] != NULL && $_POST['color'] != NULL) {
echo '<p class="welcomemessage">Welcome back: '.$myname.', your favorite color is '.$mycolor.'. </p>';
}

?>

</body>