Ken
Ken

Reputation: 15

Input type hidden value not displaying in PHP while Loop

I am trying to get values from input type hidden using PHP while loop to retrieve data on result page. Everything is working fine except the values within the input field.

Here's my code

        <?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 } ?>

Now the problem is when I click submitted button it takes me to result page with the following error

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result

When I inspect element on Firefox so it shows the blank value

enter image description here

But when I manually assign some random id numbers eg: 1,2,3 to the value field then everything works fine on result page, so the problem is only the values are not being displayed from the PHP while Loop.

What am I missing?

Upvotes: 1

Views: 484

Answers (1)

Don&#39;t Panic
Don&#39;t Panic

Reputation: 14520

You are simply missing an echo:

<?php echo $tid;?>

Upvotes: 2

Related Questions