batristio
batristio

Reputation: 160

"hidden" type input value, not being send correctly via $_POST

I was wondering why I am not sending the value of the hidden input? After the browser executes the following code, I actually get the desired ID in the value tag - see the image here.

if (mysqli_num_rows($allStreets) > 0) {
  while ($display = mysqli_fetch_assoc($allStreets)){
    echo <<< HEREDOC
    <form action="allHouses.php" method="post">
      <table class='table table-striped'>
        <tr>
          <td align="left">
            {$display["name"]}
          </td>
          <td align="right">
            <input type="submit" class="btn btn-success" name="street" value="Go to all houses on this street">
            <input type="hidden" name="id" value"{$display['id']}">
          </td>
        </tr>
      </table>
    </form>
HEREDOC;
  }
} else {
  echo "No streets found";
}

And then I have a php code that doest the following:

if (isset($_POST['id'])) {
  echo var_dump($_POST['id']);
  echo "set";
} else {
  echo "not set";
}

And the output from the var_dump() is: string(0) "" set. Not 2 as I expect.
My question is why it is not holding the ID? And how could this be fixed? Thank you!

Upvotes: 0

Views: 83

Answers (1)

Marcos Casagrande
Marcos Casagrande

Reputation: 40444

You're missing = in value.

change this

value"{$display['id']}"

with this:

value="{$display['id']}"

Upvotes: 2

Related Questions