在PHP / MySQL中使用下拉菜单预填充表单?

I am creating a simple CRUD application that will be used as a blog. For the edit page, I want to have a dropdown menu with the blog titles of each post. When an option/blog post is selected, I want it to populate the "Title" and "Message" fields, so it can then be edited and saved to the database.

I got it to retrieve the titles of the blog posts, but I am struggling to make it populate the "Title" and "Message" fields so it can be edited when the option is selected.

I have 4 rows in my database: row[0] is the title, row[1] is the message, row[2] is the timestamp and row[3] is the ID.

Thanks guys. I appreciate it.

    <form action="edit.php" id="myform" method="post" autocomplete=off>
      <input type="hidden" name="action" value="show">

      <p><label>Entry:</label><select name="blog">
      <?php

          $result = mysqli_query($con, "SELECT * FROM blog");
          while ($row = mysqli_fetch_array($result)) {
              $chosen = $row['bid'];
          }

          if (isset($_GET['blog'])) {
                $id = $_GET['blog'];
                $result = mysqli_query($con, "SELECT * FROM blog WHERE bid='$id'");
                $row = mysqli_fetch_array($result);
          }

          $result = mysqli_query($con, "SELECT * FROM blog");
          while ($row = mysqli_fetch_array($result)) {
              $id = $row['bid'];
              $title = $row['title'];

              $selected = '';
              if ($id == $chosen) {
                  $selected = "selected='selected'";
              }

              echo "<option value='$id' $selected>$title</option>
";
          }

      ?>
    </select></p>

  <p><label>Title:</label> <input type="text" id="newtitle" name="newtitle" value="<?php echo $row[0]; ?>"></p>
  <p><label>Message:</label> <input type="text" id="newmessage" name="newmessage" value="<?php echo $row[1]; ?>"></p>
  <p><input type="hidden" name="id" value="<?php echo $row[3]; ?>"></p>

  <br><p><input type="submit" name="submit" value="Submit"></p>
</form>

I have managed to somewhat figure out the answer on my own. It's probably not the most ideal way of doing it, but for anyone else potentially stuck on this - here is my code:

The only issue I'm having now is figuring out how to keep my option selected.

    <form action="edit.php" id="myform" method="post" autocomplete=off>
      <input type="hidden" name="action" value="show">

      <p><label>Entry:</label><select name="blog" onchange="window.location.href = blog.options[selectedIndex].value">
          <option selected disabled>Select One</option>
      <?php
          $result = mysqli_query($con, "SELECT * FROM blog");
          while ($row = mysqli_fetch_array($result)) {
              $id = $row['bid'];
              $title = $row['title'];

              echo "<option value='edit.php?edit=$row[bid]'>$title</option>
";
          }

          if (isset($_GET['edit'])) {
                $id = $_GET['edit'];
                $result = mysqli_query($con, "SELECT * FROM blog WHERE bid='$id'");
                $row = mysqli_fetch_array($result);
          }

      ?>
    </select></p>

  <p><label>Title:</label> <input type="text" id="newtitle" name="newtitle" value="<?php echo $row[0]; ?>"></p>
  <p><label>Message:</label> <input type="text" id="newmessage" name="newmessage" value="<?php echo $row[1]; ?>"></p>
  <p><input type="hidden" name="id" value="<?php echo $row[3]; ?>"></p>

  <br><p><input type="submit" name="submit" value="Submit"></p>
</form>