dongsu0308 2016-06-06 04:45
浏览 34

在表单中发送使用PHP定义的值的优势

EDIT: This code isnt for debugging, it is written only as an example and doesnt need completion as the point of it is just seeing the advantages of using a HIDDEN input in a form to retrieve some value. The answers may also be quick and graphic or metaphorical. I dont want a working code, just the advantages of using each methodology. I also fixed an imaginary condition to the while loop and a value for $record_id and placed them so you can understand.

<?php
    if (isset($_POST['delete_action'])) {
        $deletedRow = $_POST['row_to_be_deleted'];
        mysqli_query($connection, "DELETE FROM table_name WHERE record_id = " . $deletedRow);
        //Here is where hidden field value is used
    }

    $someSQL = "SELECT * FROM comments_tbl WHERE postID=$PostRetrievedID";

    while ($someFetch = mysqli_fetch_array($con, $someSQL)) {
        $record_id = $someFetch['comment_ID'];
        $record_content = $someFetch['comment_Content'];
        ?>

        <span>
            <?php echo $record_content; ?>
        </span>
        <form method="post">
            <input type="hidden" name="row_to_be_deleted" value="<?php echo $record_id; ?>"/>
            <input type="submit" name="delete_action" value="Delete comment"/>
        </form>

        <?php
    }
?>
  • 写回答

1条回答 默认 最新

  • dsf6281 2016-06-06 14:12
    关注

    If your question is about why hidden fields even exists, then I have to say that they are used on lots of websites for the exact reason you show in the example.

    Lots of times, when you have a form and the user submits it, you need some extra data that the user should not see so that you can manage the data the user submitted. Like in you example, one common use is to atach the ID of the row.

    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程