簡體   English   中英

從 Post Data (PHP) 中獲取變量

[英]Get variable from Post Data (PHP)

我真的不知道為什么我的代碼不起作用! 讓我舉例說明一下..

我有一個名為“index.html”的文件示例...

<html>
      <body>
            <form action="test.php" method="post">
                       Name: <input type="text" name="test">
                      <input type="submit">
             </form>
     </body>
</html>

當然還有表單操作文件 test.php .. 示例..

<?php

$something = ($_POST["test"]);

// from here I have some  PHP codes and this "something" variable will be process in this codes and will print out something spacial..
?>

現在的例子如果我發布“你好,它不起作用”那么輸出將顯示一個空間設計。 但取而代之的是過程,它只是打印出我在該表單中提交的任何內容。 但是當我手動將變量添加到 "something" 並且我執行 "test.php" 時。 例子..

$something = "Hello, It's not working";

然后它完美地工作..

是的。 也試過GET方法..它仍然與POST相同。 這是我在這里的第一個問題..感謝您的任何幫助和建議!

First Convert, index.html to php and follow this code:-

<html>
      <body>
            <form action="test.php" method="post">
                       Name: <input type="text" value="" name="test">
                      <input name="submit" value="submit" type="submit">
             </form>
     </body>
</html>


<?php
if(isset($_POST['submit'])){
  $something = $_POST["test"];
}

?>

這是正確的_POST:

<?php
//NO  ($_POST["test"])
$something = $_POST["test"];

?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM