如何在单个表单中包含多个变量

时间:2013-03-26 07:05:36

标签: php input

这是我到目前为止所做的:

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皮划艇运动员,你今年的对手是:|或者,你是一个小型皮划艇呃。你今年的对手是:

2 个答案:

答案 0 :(得分: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";
?>

无线电形式的价值必须是划独木舟和“皮划艇”。只需添加$ck = $_POST['ck'];,您的句子就像echo "a $ck Atom.";

答案 1 :(得分: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;
   ?>