douchen1924 2015-02-05 07:03
浏览 34
已采纳

我发布时变量没有显示在字符串中?

This is the HTML Page for my mad lib form where I have a form to fill out a mad lib. Once the user fills out the form he will submit and it should return with the completed mad lib.

<head>

    <title>This page sends the data</title>

</head>

    <body>
        <em><h1>Hip-Hop Mad Libs</h1></em>

        <form action="page2.php" method="post">
            <!--1-->
            <label for="clothing">Item of clothing:</label><br>

            <input type="text" name="clothing" id="clothing">


            <br><br>
            <!--2-->
            <label for="adj1">Adjective:</label><br>

            <input type="text" name="adj1" id="adj1">


            <br><br>
            <!--3-->
            <label for="verb1">-ing Verb</label><br>

            <input type="text" name="verb1" id="verb1">


            <br><br>
            <!--4-->
            <label for="verb2">-ed Verb</label><br>

            <input type="text" name="verb2" id="verb2">


            <br><br>
            <!--5-->
            <label for="nickname">Nickname:</label><br>

            <input type="text" name="nickname" id="nickname">

            <br><br>

            <!--6-->
            <label for="race">Race of people:</label><br>

            <input type="text" name="race" id="race">


            <br><br>
            <!--7-->
            <label for="valued">Thing OF Value:</label><br>

            <input type="text" name="valued" id="valued">


            <br><br>
            <!--8-->
            <label for="body">Body Function:</label><br>

            <input type="text" name="body" id="body">


            <br><br>
            <!--9-->
            <label for="verb3">-ed Verb:</label><br>

            <input type="text" name="verb3" id="verb3">


            <br><br>
            <!--10-->
            <label for="woman">Famous Woman:</label><br>

            <input type="text" name="woman" id="woman">


            <br><br>

            <!--11-->
            <label for="occupation">Odd Occupation:</label><br>

            <input type="text" name="occupation" id="occupation">


            <br><br>

            <!--12-->
            <label for="occupation2">Same Occupation:</label><br>

            <input type="text" name="occupation2" id="occupation2">


            <br><br>
            <!--13-->
            <label for="body2">Body Part:</label><br>

            <input type="text" name="body2" id="body2">


            <br><br>
            <!--14-->
            <label for="behavior">Behavior:</label><br>

            <input type="text" name="behavior" id="behavior">


            <br><br>
            <!--15-->
            <label for="nickname2">Mean Nickname:</label><br>

            <input type="text" name="nickname2" id="nickname2">


            <br><br>
            <!--16-->
            <label for="verb4">-ed Verb:</label><br>

            <input type="text" name="verb4" id="verb4">


            <br><br>
            <!--17-->
            <label for="body3">Body Part:</label><br>

            <input type="text" name="body3" id="body3">


            <br><br>



            <button type="submit">Submit</button>

        </form>
        <img src="madlib.jpg" style= "width: 600px;heigth:600px" >

</body>

Here is the PHP where the variables are posted to create the mad lib but when I click submit on the form it only shows the paragraph without the variables

<?php
            $clothing = $_GET["clothing"];
            $adj1 = $_GET["adj1"];
            $verb1 = $_GET["verb1"];
            $verb2 = $_GET["verb2"];
            $nickname = $_GET["nickname"];
            $race = $_GET["race"];
            $valued = $_GET["valued"];
            $body = $_GET["body"];
            $verb3 = $_GET["verb3"];
            $woman = $_GET["woman"];
            $occupation = $_GET["occupation"];
            $occupation2 = $_GET["occupation2"];
            $body2 = $_GET["body2"];
            $behavior = $_GET["behavior"];
            $nickname2 = $_GET["nickname2"];
            $verb4 = $_GET["verb4"];
            $body3 = $_GET["body3"];


            $message= "Once upon a time not long ago, where people wore $clothing and
       lived life slow, when were $adj1 and justice stood, and people were $verb1 like they ought ta good. There lived a little boy who was $verb2 by another little boy and this is what he said: Me and you,$nickname we're gonna make  some cash, robbing $race and making a dash.They did the job, $value came with ease. But one couldn't $body. It's like he had a disease. He $verb3 another and another and $woman and her brother;tried to rob a man who a/am $occupation. The $occupation2 grabbed his $body2 he started acting $behavior.He said, Keep still, $nickname2, no need for static, $verb4 him in his $body3 and he gave him a slap.";


        echo $message;              
        ?>
  • 写回答

6条回答 默认 最新

  • duandanbeng1829 2015-02-05 07:06
    关注

    use $_POST instead of $_GET variable in your PHP code.

    $clothing = $_POST["clothing"];
    $adj1 = $_POST["adj1"];
    $verb1 = $_POST["verb1"];
    $verb2 = $_POST["verb2"];
    ...
    

    You use $_GET variable only when your form has no method set or is set to get <form method="get">. You usually use $_GET variables if you are dealing with query strings. That is the texts that you see in the URLs after the domain. e.g. http://google.com/search?query_sting=value.

    If you don't want the data to be exposed in the url after submit, use <form method="post"> and access data in PHP using $name=$_POST['name']

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效