2017-07-08 83 views
1

我只是試圖在第一個文本框中輸入一個單詞或數字,並在單擊提交後將該單詞存儲在變量中,然後回傳到第二個文本框中。這是我有的代碼,但它不工作。文本框的PHP設置值等於表單變量

<html> 
<head> 
    <?php 
     $one = ""; 
     if (isset($_POST["Submit"])){ 
      $one = $_POST["inputOne"]; 
     } 
    ?> 
</head> 

<body> 
    <form method="post" action="index.php"> 
     <input type="text" name="inputOne"> 
     <input type="submit" name="Submit"> 
     <input type="text" name="output" value="<?php echo $one; ?>"> 
    </form> 
</body> 
</html> 
+0

你命名該文件作爲'index.php'? –

+0

您的代碼工作.. – threeFatCat

+0

我沒有看到任何代碼錯誤。它以什麼方式「不起作用」?具體發生了什麼? – David

回答

0

你試過從action移除index.php,只是空白?起初,它沒有工作,但後來我刪除的index.php:

<html> 
<head> 
    <?php 
     $one = ""; 
     if (isset($_POST["Submit"])){ 
      $one = $_POST["inputOne"]; 
     } 
    ?> 
</head> 
<body> 
    <form method="post" action=""> 
     <input type="text" name="inputOne"> 
     <input type="submit" name="Submit"> 
     <input type="text" name="output" value="<?php echo $one; ?>"> 
    </form> 
</body> 
</html> 
0

嘗試:

if(isset($_POST["inputOne"])){ $one = $_POST["inputOne"]; 
}else{$one = 'No value was sent for inputOne';} 

......這個你的PHP將讓你知道如果inputOne一個值從來沒有收到過。

老實說..你正在努力實現的是什麼,你的代碼應該看起來更像是這樣的:

<html> 
<head> 
    <?php 
     $one = ""; 
     if (isset($_POST["inputOne"])){ 
      $one = $_POST["inputOne"]; 
     }else{$one = 'No value received for one';} 
    ?> 
</head> 
<body> 
    <form method="post" action=""> 
     <input type="text" name="inputOne"> 
     <input type="submit" name="Submit"> 
     <input type="text" name="output" value="<?php echo $one; ?>"> 
    </form> 
</body> 
</html> 
相關問題