I'm practicing with PHP and tried to design a simple program. If the user types "red" or "blue" into the textfield and hits "submit", the program is supposed to print "Your favorite color is red" or "Your favorite color is blue." But for some reason it doesn't work.
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
$favcolor = $_GET["favcolor"];
switch($favcolor){
case "red":
echo "Your favorite color is red!";
break;
case "blue":
echo "Your favorite color is blue!";
}
?>
<form action = "index.php" method = "post">
<input type ="text" name="favcolor">
<input type ="submit" name="submit">
</form>
</body>
However, I get this error "Notice: Undefined index: favcolor in C:\xampp\htdocs\Fav_Colors\index.php on line 14"
What's the deal?