2015-04-01 73 views
-1

傳遞值這是我在test1.php不能選擇選項

<?php 
if ($_POST['check']!= ""){ 
$a = $_POST['translation']; 

} 
?> 
<html> 
<form action="test2.php" method="post"> 
<select name="translation"> 
<option selected="selected" value="1">Vietnamese-English</option> 
<option value="2">English-Vietnamese</option> 
</select> 
<input type="submit" value="Check" name="check"> 
</form> 
</html> 

代碼和test2.php我只是回顯值$a,但我什麼也沒得到。該值爲NULL,當我使用var_dump($a)

+1

如果您將表單發送到test2.php,您認爲'$ a'如何設置? – Rizier123 2015-04-01 18:46:25

+0

$ a將具有從2個選項中的用戶中選擇的值 – vendetta 2015-04-01 18:49:44

+0

不會達到此代碼,因爲如果您提交表單 – Rizier123 2015-04-01 18:50:35

回答

0

在窗體的這部分代碼,不屬於那裏:

<?php 
if ($_POST['check']!= ""){ 
$a = $_POST['translation']; 

// echo $a; // I added this 
} 
?> 

它屬於你test2.php文件,這就是爲什麼你沒有得到結果。