Я пытаюсь создать эту страницу, которая дает разные комментарии, когда различные значения массы (из кошек: 3) передаются с использованием if и else if. Однако комментарий не появляется, когда я попал в submit, и я не мог понять проблему.php using if и else if statement
Это мой код:
<?
if ($_POST['subBtn']) {
$mass = $_POST['theMass'];
$colour = $_POST['theColour'];
$name = $_POST['theName'];
$comment = $_POST['theComment'];
echo "<p> The name of the cat is <b>" . $name . "</b>, the colour is <b>" . $colour . "</b>, the mass is <b>" . $mass . "." . $comment . "</p>";}
?>
<?
if ($_POST['subBtn']) {
$mass = $_POST['theMass'];
if ($mass <= 0 AND NULL) {
$comment = "INVALID";
} else if ($mass >= 0 AND $mass <=2.5) {
$comment = "Skin and bones!!!";
} else if ($mass > 2.5 AND $mass<=5) {
$comment = "Small but healthy";
} else if ($mass > 5 AND $mass<=10) {
$comment = "Getting a little heavy!";
} else if ($mass >10 AND $mass<=15) {
$comment = "You may wanna hide the food!";
} else if ($mass >15 AND $mass<=20) {
$comment = "Are you sure this is a cat?";
} else if ($mass >20) {
$comment = "Need another job too feed your cat! <p>'Comment: OMG'</p>";
} else {
$comment = "<p class='error'>Nothing specific to comment...sorry try again</p>";
}
}
?>
<p>
<form action="crazy-cats.php" method="post">
Colour of the Cat:
<select name="theColour">
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
<option value="black">Black</option>
</select>
Mass: <input type="text" name="theMass" value="" /><br />
<br />
Name: <input type="text" name="theName" value="" /><br />
<input type="submit"name="subBtn" value="submit"/></input>
</form>
</p>
ваш отсутствует 'эхо $ комментарий;' ' –
elseif' все одно слово – Derek
@OliverQueen его в силе, как 2 http://php.net/manual/en/control-structures.elseif.php –