The code:
<!DOCTYPE html>
<html>
<head>
<title>Greeting Service!</title>
</head>
<body>
<center>
<form method="post" action="">
<h1>What's Your Name?</h1>
<input type="text" name="name" placeholder="Name Here" />
<h4>Greet me in:
<select name="language">
<option value="option1">English</option>
<option value="option2">Chinese</option>
<option value="option3">French</option>
</select>
</h4>
<input type="submit" value="Greet Me!" />
<?php
if (isset($_POST['language'])) {
switch ($language) {
case "option1":
$result = "Hello, $name!";
break;
case "option2":
$result = "你好, $name!";
break;
case "option3":
$result = "Bonjour, $name!";
break;
}
}
?>
</form>
</center>
</body>
</html>
I'm not sure why it doesn't display the name i enter in from the input text box with the greeting according to each different language. I have used $_POST to submit the form and used a switch
and case
in my php code. Can someone help me out, i would like the name that is entered in the textbox to display when i have chosen which language i want the greeting to come out with. Thanks.