Mad Libs タイプの課題に取り組んでいます。教授がストーリーで使用させているカエルの名前をヒーローネームで指定しようとしていますが、何らかの理由で、カエルの名前を変更する if ステートメントが機能しません。
ヒーロー名の名前を入力しようとするたびに (「あなたの名前」を尋ねると、常にデフォルトで Taylor になり、Henry がカエルの名前になります。この if-else ステートメントを正しく機能させて名前を Henry にするにはどうすればよいですか?ヒーローネームにテイラーかジェイミーが入力された場合のみ?
HTML
<!DOCTYPE html>
<html>
<head>
<title>Mad Libs Time</title>
</head>
<body>
<h1>MAD LIBS TIME, HOMIE!</h1>
<p>Y'arr, this be a tale all about the lives of ye and yer pirate mateys. Full of adventure, loss, love, and magic this story be. In order to tell it to ye the way ya like, answer a few questions before I throw ye in the brig!</p>
<form name="gatheringinfo" method="post" action="tellthatstory.php">
Aye, what's yer name? <input type="text" name="heroname"><br/>
What be yer best matey's name? <input type="text" name="friendname"><br/>
Name the wizard of this tale: <input type="text" name="wizardname"><br/>
What be the wizard's power?<select name="power">
<option value="fire">Fire</option>
<option value="earth">Earth</option>
<option value="water">Water</option>
</select><br/>
Pick a number, 1 to 10..<select name="pickanumber">
<option value="one">1</option>
<option value="two">2</option>
<option value="three">3</option>
<option value="four">4</option>
<option value="five">5</option>
<option value="six">6</option>
<option value="seven">7</option>
<option value="eight">8</option>
<option value="nine">9</option>
<option value="ten">10</option>
</select><br/>
And lastly, before we get started, pick ye weapon...<select name="weapon">
<option value="scimitar">Scimitar</option>
<option value="musket">Musket</option>
<option value="dagger">Dagger</option>
</select><br/>
<input type="submit" name="submit" value="Spin Me A Tale"/>
</form>
</body>
</html>
PHP
<?php
$heroname=$_POST['heroname'];
$friendname=$_POST['friendname'];
$wizardname=$_POST['wizardname'];
$power=$_POST['power'];
$pickanumber=$_POST['pickanumber'];
$weapon=$_POST['weapon'];
switch ($power) {
case "fire":
$power="Fire";
$fight_sentence=2;
break;
case "earth":
$power="Earth";
$fight_sentence=4;
break;
case "water":
$power="Water";
$fight_sentence=6;
break;
}
$frogstory = array("", "", "", "", "", "", "", "", "", "");
switch ($pickanumber) {
case "one":
$reasonforfrog="frogstory[0]";
break;
case "two":
$reasonforfrog="frogstory[1]";
break;
case "three":
$reasonforfrog="frogstory[2]";
break;
case "four":
$reasonforfrog="frogstory[3]";
break;
case "five":
$reasonforfrog="frogstory[4]";
break;
case "six":
$reasonforfrog="frogstory[5]";
break;
case "seven":
$reasonforfrog="frogstory[6]";
break;
case "eight":
$reasonforfrog="frogstory[7]";
break;
case "nine":
$reasonforfrog="frogstory[8]";
break;
case "ten":
$reasonforfrog="frogstory[9]";
break;
}
switch ($weapon) {
case "scimitar":
$weapon="scimitar";
break;
case "musket":
$weapon="musket";
break;
case "dagger":
$weapon="dagger";
break;
}
if($heroname="Taylor"):
$frogname="Henry";
elseif($heroname="taylor"):
$frogname="Henry";
elseif($heroname="Jamie"):
$frogname="Henry";
elseif($heroname="jamie"):
$frogname="Henry";
else: $frogname="Matthew";
endif;
echo " The day the fearless pirate $heroname and the fearless friend $friendname took their first step offshore, they never knew the adventures the future would hold for them both. They plundered and pillaged for years and years, always getting their fill of the booty and rum that flowed effortlessly into their lives. Just as they were getting used to all of the excitement.. just as they were about to cash out.. just as they were about to transfer back to life on land.. they were approached by their superior, Captain Rumbeard.<br/>
He told $heroname and $friendname that he was visited by the wizard $wizardname in a dream and was told where the biggest treasure trove he'd ever heard of lied in wait. $frogname";
?>