Loop时输入类型隐藏值不显示在PHP中

问题描述 投票:1回答:1

我试图从输入类型隐藏使用PHP while循环来检索结果页面上的数据。除输入字段中的值外,一切正常。

这是我的代码

        <?php 
        $sql = "SELECT id,title FROM data ORDER BY id DESC LIMIT 10";
        $result = mysqli_query($conn, $sql);
        while ($row = mysqli_fetch_array($result)) {
        $tid = $row['id'];
        $title = $row['title'];
        ?>  
        <li>
            <div class="opt-text-w3layouts">
            <form action="/results.php" method="POST">
                <span style="padding:0 5px 10px 0px; word-wrap: break-word;"> 
                    <input type="hidden" name="id" value="<?php $tid;?>">
                    <button type="submit"><?php echo $title; ?></button>
                </span>
            </form>
            </div>          
        </li>
        <?php } ?>

现在的问题是,当我点击提交按钮时,它将带我到结果页面,出现以下错误

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result

当我在Firefox上检查元素时,它显示空白值

enter image description here

但是当我手动将一些随机id号码(例如:1,2,3)分配给值字段时,结果页面上的所有内容都能正常工作,因此问题只是在循环时没有显示PHP中的值。

我错过了什么?

php forms input
1个回答
2
投票

你只是错过了一个echo

<?php echo $tid;?>
© www.soinside.com 2019 - 2024. All rights reserved.