2015-01-26 48 views
1

我通過POST方法使用href鏈接提交表單。當我提交表單時,我無法獲得PHP變量的值。如何在使用href提交表單後在同一頁上獲取文本?

這裏是我的代碼

 if(($_POST)) { 
    $users1 = $_POST['cityname']; 
    echo $users1; 
    echo "shakti"; 
} 

<td align="center"> 
<form action="searchresult.php" method="POST"> 

<a href="#" style="text-decoration:none;" onclick="parentNode.submit();" name="an"> 
    </form> 
     <?php echo $row['city']; ?> 
    <input type="text" value="<?php echo $row['city'];?>" name="cityname"> 
    </a> 
     </td> 

我怎樣才能實現我想要的輸出?

謝謝!

回答

1

表單元素裏面的錨標記是無效的HTML

if(($_POST)) { 
    $users1 = $_POST['cityname']; 
    echo $users1; 
    echo "shakti"; 
} 

    <td align="center"> 
    <form action="searchresult.php" name="form1" method="POST"> 
     <?php echo $row['city']; ?> 
    <input type="text" value="<?php echo $row['city'];?>" name="cityname"> 
    <a href="#" style="text-decoration:none;" onclick="javascript:document.form1.submit();" name="an">SUBMIT</a> 
</form> 
     </td> 
相關問題