0

这是我到目前为止所拥有的:

Age: <input type="text" name="age">

   Canoe<input type="radio" name="ck">
        Kayak<input type="radio" name="ck">


<input type="submit" style=" margin-bottom: 30px;">
</form>

You are <?php $_POST["age"];
 if ($_POST["age"]<"11")
 echo "an Atom.";

 elseif ($_POST["age"]<"13")
 echo "a Peewee.";

 elseif ($_POST["age"]<"15")
 echo "a Bantam.";

 elseif ($_POST["age"]<"17")
 echo  "a Midget.";

 elseif ($_POST["age"]<"19")
 echo "a Juvenile.";

 elseif ($_POST["age"]<"21")
 echo "a Junior.";

 elseif ($_POST["age"]<"120")
 echo "a Senior.";

 elseif ($_POST["age"]>"120")
 echo "too old to race";
   ?>   

我希望能够在其中包含独木舟和皮划艇单选按钮,以使输出类似于:您是 Peewee 独木舟运动员,今年您的对手是:| 或者,你是一个侏儒皮划艇运动员。今年你的对手是:

4

2 回答 2

1

您是否尝试将 CK 值回显到您的输出中?这有帮助吗?

Age: <input type="text" name="age">

Canoe<input type="radio" name="ck" value="canoeist">
Kayak<input type="radio" name="ck" value="kayakist">

<input type="submit" style=" margin-bottom: 30px;">
</form>

<?php
        $ck = $_POST["ck"];
?>

You are <?php $_POST["age"];
if ($_POST["age"]<"11")
echo "a $ck Atom.";

elseif ($_POST["age"]<"13")
echo "a $ck Peewee.";

elseif ($_POST["age"]<"15")
echo "a $ck Bantam.";

elseif ($_POST["age"]<"17")
echo  "a $ck Midget.";

elseif ($_POST["age"]<"19")
echo "a $ck Juvenile.";

elseif ($_POST["age"]<"21")
echo "a $ck Junior.";

elseif ($_POST["age"]<"120")
echo "a $ck Senior.";

elseif ($_POST["age"]>"120")
echo "too old to race";
?>

形式 radio 的值必须是 canoeist 和 "kayakist"。只需加上$ck = $_POST['ck'];你的句子就像echo "a $ck Atom.";

于 2013-03-26T07:29:15.970 回答
0

你应该在这里使用一些变量。

(我不是很擅长 php,但我会尝试一下)

Age: <input type="text" name="age">

    Canoe<input type="radio" name="ck" value="canoe"/>
    Kayak<input type="radio" name="ck" value="kayak"/>

<input type="submit" style=" margin-bottom: 30px;">
</form>

$boat = "";
if ($_POST["ck"] == "canoe")
{
    $boat = "canoeist";
} else if ($_POST["ck"] == "kayak")
{
    $boat = "kayak er";
}


$rank = "";
You are <?php $_POST["age"];
 if ($_POST["age"]<"11")
 $rank = "an Atom.";

 elseif ($_POST["age"]<"13")
 $rank = "a Peewee.";

 elseif ($_POST["age"]<"15")
 $rank = "a Bantam.";

 elseif ($_POST["age"]<"17")
 $rank =  "a Midget.";

 elseif ($_POST["age"]<"19")
 $rank = "a Juvenile.";

 elseif ($_POST["age"]<"21")
 $rank = "a Junior.";

 elseif ($_POST["age"]<"120")
 $rank = "a Senior.";

 elseif ($_POST["age"]>"120")
 $rank = "too old to race";

 echo "You are " . $rank . " " . $boat;
   ?>   
于 2013-03-26T07:27:50.793 回答