2015-02-05 49 views
0

這是我的瘋狂lib窗體的HTML頁面,我有一個表格來填寫一個瘋狂的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> 

這裏就是變量被髮布到創建狂lib中的PHP,但是當我點擊提交表單上只顯示沒有變量的段落

<?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;    
     ?> 
+0

用戶$ _REQUEST而不是$ _GET .. –

回答

0

使用$_POST而不是$_GET變量在您的PHP代碼中。

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

您可以使用只有當你的表單沒有方法集,或者設置爲獲得​​$_GET變量。如果您正在處理查詢字符串,則通常使用$_GET變量。這是您在域名後面的網址中看到的文字。例如http://google.com/search?query_sting=value

如果你不希望數據在URL中暴露後提交,使用$name=$_POST['name']

0

您正在使用POST作爲窗體的方法並嘗試使用$_GET訪問,您需要訪問使用$_POST值,因此改爲

$clothing = $_POST["clothing"]; 
... 
0

爲了你的代碼工作

<form action="page2.php" method="post"> 

必須改成:

<form action="page2.php" method="get"> 

或在您的PHP使用$ _ POST變量:

$clothing = $_POST["clothing"]; 
    .... 
0

您使用POST方法,所以你應該使用的代碼中使用<form method="post">和訪問數據的PHP做。

<?php 
      $clothing = $_POST["clothing"]; 
      $adj1 = $_POST["adj1"]; 
      $verb1 = $_POST["verb1"]; 
      $verb2 = $_POST["verb2"]; 
      $nickname = $_POST["nickname"]; 
      $race = $_POST["race"]; 
      $valued = $_POST["valued"]; 
      $body = $_POST["body"]; 
      $verb3 = $_POST["verb3"]; 
      $woman = $_POST["woman"]; 
      $occupation = $_POST["occupation"]; 
      $occupation2 = $_POST["occupation2"]; 
      $body2 = $_POST["body2"]; 
      $behavior = $_POST["behavior"]; 
      $nickname2 =$_POST["nickname2"]; 
      $verb4 = $_POST["verb4"]; 
      $body3 = $_POST["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;    
     ?> 
0

如果讓我選擇,我可能不會使用$_REQUEST,我會選擇$_GET$_POST - 這取決於我的應用程序應該做的事情(i.e. one or the other, but not both):一般來說:

  • 你應該當有人從您的應用程序請求數據時使用$_GET
  • 而當有人推送(插入或更新;或刪除)數據到您的應用程序時,您應該使用$_POST

所以,只要在你的代碼更改:

<form action="page2.php" method="get"> 
0

您使用POST方法,並與GET所獲得的價值 提交表單method.you應該得到兩個或POST都..

相關問題