PHP回发提交

时间:2012-11-04 22:02:31

标签: php forms submit postback

我对php postback有疑问

我的代码是:

<?php
if(isset($_POST["Delete"]))
{  
   echo "DELETE";
}

if(isset($_POST["Modifier"]))
{  
   echo "Modifier";
}

if(!empty($_SESSION["Status"]))
{
    if($_SESSION["Status"] == "u")
    {
        header("Location: Index.php?Action=Acceuil");
    }

    if($_SESSION["Status"] == "a")
    {
        $Connection = mysql_connect("localhost","root") or die(mysql_error());                
        mysql_select_db("tpw34") or die("Nope.");                
        $query = "Select * From Products";
        $result = mysql_query($query);


        While($ligne = mysql_fetch_assoc($result))
        {
            //Index.php?Action=AdminDeleteProduct&Delete=".$ligne["ProductID"]."
            echo "<form method='POST' Action='#'>";
                echo "<table border='1'>";
                echo "<tr>";
                echo "<td colspan='2'><center><img  width='250' height='250' src='".$ligne["Image"]."'/></center></td>";
                echo "</tr>";
                echo "<tr>";
                    echo "<th>Nom du produit :</th>";
                    echo "<td>".$ligne["ProductName"]."</td>";
                echo "</tr>";
                echo "<tr>";
                    echo "<th>Prix :</th>";
                    echo "<td>".$ligne["Prix"]."</td>";
                echo "</tr>";
                echo "<tr>";
                    echo "<th>Description :</th>";
                    echo "<td>".$ligne["Description"]."</td>";
                echo "</tr>";
                echo "<tr>";
                    echo "<td colspan='2'h><input type='Submit' value='Delete' name='Delete'/><input type='Submit' value='Modifier' name='Modifier'/></td>";
                echo "</tr>";
                echo "</table>";
                echo "<br>";
            echo "</form>";
        }
    }
}

?>

我的问题是:我希望将项目的ProductID(在表格中)放在$_POST["Delete"]$_POST["Modifier"]中,但我不想更改按钮上的文字。我想保留DELETE和MODIFIER。我在网上看过很多东西,但我找不到正确的答案。

2 个答案:

答案 0 :(得分:0)

包含ProductID的隐藏表单值。然后你可以检索$ _POST ['ProductID']

中的值
 echo "<input type=hidden name='ProductID' value='" . $ligne["ProductID"] . "'>";

答案 1 :(得分:0)

您可以使用会话,您可以暂时保存信息。

Sessions

或者像Tim Dearborn建议的那样,使用隐藏的输入将其与下一个表单提交一起发送。

相关问题