簡體   English   中英

PHP - 如何從隱藏輸入類型和$ _POST到另一個PHP獲取名稱?

[英]PHP - How can I get the name from input type hidden and $_POST to another php?

我希望可以將getvenueurl的值getvenueurl給另一個名為map.php的php。

我使用隱藏的輸入類型來回顯當前頁面:

<input type="hidden" name="getvenueurl" value="<?php echo $show_venue['url']; ?>"/>

我希望當我點擊按鈕<a href="map.php" target="_blank"><input type="button" class="button" value="MAP" style="width:100px;"> in map.php顯示的正確值getvenueurl

在當前頁面中:

 <?php
$read_venue = mysql_query("select * from venue where theme_name = '$title'");

while($show_venue = mysql_fetch_array($read_venue)) 
{

?>
<form method="post" action="#tab5">
<center><table border="1" class="venuetb">

    <tr>
        <input type="hidden" name="getvenue" value="<?php echo $show_venue['venue']; ?>"/>
        <input type="hidden" name="getvenueprice" value="<?php echo $show_venue['price']; ?>"/>
        <input type="hidden" name="getvenueurl" value="<?php echo $show_venue['url']; ?>"/>

        <td style="width:20%;"><center><div class="imgvenue"><img src="<?php echo 'venueimg/'.$show_venue['venueimg']; ?>" /></div></center></td>

        <td ><center><div class="bine"><?php echo $show_venue['venue']; ?> - RM <?php echo $show_venue['price']; ?></div></center></br>
        <div class="dv"><p>&nbsp;<b>Address : </b><?php echo $show_venue['address']; ?></p>
        <p>&nbsp;<b>Detail : </b><?php echo $show_venue['detail']; ?></p>
        <b>&nbsp;Contact No: </b><?php echo $show_venue['contact']; ?></div>
        </td>
        <td style="width:20%;">
        <center><a href="map.php" target="_blank"><input type="button"  class="button" value="MAP" style="width:100px;"></a>
        <input type="submit" class="button" style="width:100px;" value="CHOOSE" name="choose_venue"></center>


        </td>

    </tr>
        </table></center><br>
</form>
<?php
        $_SESSION['theurl'] = $show_venue['url']; 

}   
?>

<?php 
    if(isset($_POST['choose_venue']))
{
    $getvenue = $_POST['getvenue'];
    $getvenueprice = $_POST['getvenueprice'];



    $savevenue = mysql_query("insert into selectvenue(user,title,venuename,venueprice) values('$username','$title','$getvenue','$getvenueprice')");
    if($savevenue)
        {
            echo"<center>$getvenue  save.</center>";

        }
        else
        {
            echo "Failed.";

        }
}
?>
</div>

我嘗試使用session傳遞getvenueurl的值,但看到它失敗了,因為它只顯示while循環中所有輸出的最后一列值。

在map.php中:

    <table class="mapping">
    <tr>
    <td>
        <?php
        $theurl = $_SESSION['theurl'];
         echo $theurl;?>
    </td>
    </tr>
</table>

如何獲得map.php的正確值?

你可以用這種方式通過錨標簽傳遞價值。我希望這會對你有所幫助。

<a  href="map.php?getvenueurl=<?php echo $show_venue['url']; ?>" target="_blank"><input type="button"  class="button" value="MAP" style="width:100px;"></a>

代替

 <a href="map.php" target="_blank"><input type="button"  class="button" value="MAP" style="width:100px;"></a>

寫下這段代碼

<input type="button"  class="button" onclick="submit_to_map()" value="MAP" style="width:100px;">

然后將此javascript代碼放在頁面上。

<script type="text/javascript">
function submit_to_map() {
    var form = document.getElementById("form-id");
    form.action = "map.php";
    form.submit();
}
</script>

然后,您可以使用map.php中的表單內的$ _POST []獲取所有元素的值。 希望這個能對您有所幫助

確認你有<?php session_start(); ?> <?php session_start(); ?>每頁開頭!

暫無
暫無

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

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