【问题标题】:PHP postback on submit提交时的 PHP 回发
【发布时间】:2012-11-04 22:02:31
【问题描述】:

我有一个关于 php 回发的问题

我的代码是:

<?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。我在网上阅读了很多东西,但我没有找到正确的答案。

【问题讨论】:

    标签: php forms submit postback


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      您可以使用会话来临时保存您的信息。

      Sessions

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-08-28
        • 2016-02-05
        • 2017-01-20
        • 1970-01-01
        • 1970-01-01
        • 2010-10-14
        • 2015-11-16
        相关资源
        最近更新 更多