1

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?

1 Answer 1

2

You are simply missing an echo:

<?php echo $tid;?>
Sign up to request clarification or add additional context in comments.

3 Comments

Opss it took me 1 hour to look into the issue, and yes I missed the echo part, anyways thanks @Don't Panic it works now.
@Ken Happy to help, and welcome to Stack Overflow. If this answer or any other one solved your issue, please mark it as accepted.
Yes I just did because accepting an answer will have to for 8 minutes so I just did, and If you think I have input the effort for this question so you can vote up my question and thanks once again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.