如何从隐藏的输入类型和$_POST中获取名称到另一个PHP


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

我希望可以将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;">在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>

我尝试使用会话来传递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(); ?>