php中的isset()无效

时间:2017-09-19 04:21:42

标签: php mysql isset

我可以知道为什么我的isset块中的回声没有出现吗? 是因为我在php中回显我的html代码的方式吗?任何解释都将非常感激。

以下是我的代码:

<?php

    while($row = mysqli_fetch_array($result))
    {
        echo "<tr>";
        echo "<td>" . $row[1] . "</td>";
        echo "<td>" . $row[2] . "</td>";
        echo "<td>" . $row[3] . "</td>";
        echo "<td>" . $row[4] . "</td>";
        echo "<td>" . $row[5] . "</td>";
        echo "<td>" . $row[6] . "</td>";
        echo "<td>" . $row[7] . "</td>";
        echo "<td>
              <ul class=\"form-style-1\">
                <select name=\"option_update\" class=\"field-select\">
                    <option value=\"approved\">Approve</option>
                    <option value=\"declined\">Decline</option>
                    <option value=\"pending\">Pending</option>
                </select>
                <input type=\"submit\" value=\"update\" name=\"update_value\"/>
              </ul>
            </td>";
        echo "</tr>";

    }
?>
</table>
<?php

    if(isset($_POST['update_value'])){

        echo "test";
    }

?>

2 个答案:

答案 0 :(得分:0)

试试这个:        

    while($row = mysqli_fetch_array($result))
    {
        echo "<tr>";
        echo "<td>" . $row[1] . "</td>";
        echo "<td>" . $row[2] . "</td>";
        echo "<td>" . $row[3] . "</td>";
        echo "<td>" . $row[4] . "</td>";
        echo "<td>" . $row[5] . "</td>";
        echo "<td>" . $row[6] . "</td>";
        echo "<td>" . $row[7] . "</td>";
        echo "<td>
            <form action="#" method="post"> 
              <ul class=\"form-style-1\">
                <select name=\"option_update\" class=\"field-select\">
                    <option value=\"approved\">Approve</option>
                    <option value=\"declined\">Decline</option>
                    <option value=\"pending\">Pending</option>
                </select>
                <input type=\"submit\" value=\"update\" name=\"update_value\"/>
             **</form>**
              </ul>
            </td>";
        echo "</tr>";

    }
?>
</table>
<?php

    if(isset($_POST['update_value'])){

        echo "test";
    }

?>

答案 1 :(得分:0)

要从$ _POST获取变量,您必须从HTML表单

提交它们
<form method="post"> 

https://www.w3schools.com/php/php_forms.asp