doulu1914 2013-11-27 14:31
浏览 22

如何在另一个页面中获取变量?

Its not just a variable, the situation's like this:

mysql_connect("localhost", "root", "") or die (mysql_error ());
mysql_select_db("tHofbrouwerijke") or die(mysql_error());
$strSQL = "SELECT * FROM bieren";
$rs = mysql_query($strSQL);
   while($row = mysql_fetch_array($rs)) 
    {echo "<form action='RemoveBier.php' method='POST'><button type='submit' name=".$row['Naam'].">Verwijderen</button> &nbsp &nbsp".$row['Naam']."<br>";}
echo "</form>";
?>

so I used a while loop to get items from a database, and I want to use the name of the button to identify which item I have to delete. When I go to the page 'RemoveBier.php' and type in the code i think is right and try it, it does nothing. My second php page looks like this:

<?php 
include 'DeleteBier.php';
$NameButton=$row['Naam'];
mysql_connect("localhost", "root", "") or die (mysql_error ());
mysql_select_db("tHofbrouwerijke") or die(mysql_error());
echo $row['Naam'];
$strSQL = "DELETE FROM bieren WHERE naam = '.$_POST[$NameButton].'";
mysql_query($strSQL) or die(mysql_error());
header('Location: DeleteBier.php');
?>
  • 写回答

1条回答 默认 最新

  • dousuo8400 2013-11-27 14:38
    关注
    <form method="post">
        <input type="hidden" name="Beer2delete" value="SOME BEERS NAME HERE" />
        <button>Submit</button>
    </form>
    

    You now have access to the name with $_POST['Beer2delete']. Users wont see it and you have a consistent name to refer to.

    if you have multiple options, you can do it this way:

    <form method="post">
        <!-- HERE YOU LOOP, but the radiobutton so it will result in the following -->
        <input type="radio" name="beer2delete" value="beer 1" /> Beer 1 <br />
        <input type="radio" name="beer2delete" value="beer 2" /> Beer 2 <br />
        <input type="radio" name="beer2delete" value="beer 3" /> Beer 3 <br />
        <input type="radio" name="beer2delete" value="beer 4" /> Beer 4 <br />
    
        <input type="submit" name="DeleteBeer" value="Delete that delicious beer"/>
    </form>
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度