0

How to display the HTML form when the content is retrieved from the database does not exist? I have a form on a page in HTML, the form with the "select" command retrieves data from the database, when the "select" command does not receive data, the form does not appear on the page.

I want to see the template site even if the data is not returned

   <form class="form-inline" action="/action_page.php">




        <?php
      $query = "SELECT * FROM crud WHERE id=".$_SESSION['id']."";
          $stmt = $conn->prepare($query);
          $stmt->execute();
          $result = $stmt->get_result();
        ?>
        
           <?php while ($row = $result->fetch_assoc()) { ?>
           
                <a href="action.php?delete=<?= $row['id']; ?>" class="badge badge-danger p-2" onclick="return confirm('Do you want delete this record?');">Delete</a> |
                <a href="index.php?edit=<?= $row['id']; ?>" class="badge badge-success p-2">Edit</a>
              </td>
            </tr>
          
        
      </div>
    </div>
    </form>
  </nav>
  <div class="container-fluid">
    <div class="row justify-content-center">
      <div class="col-md-10">
      <span>ID:<?php echo htmlspecialchars($_SESSION["id"]); ?></span>
        <hr>
        <?php if (isset($_SESSION['response'])) { ?>
        <div class="alert alert-<?= $_SESSION['res_type']; ?> alert-dismissible text-center">
          <button type="button" class="close" data-dismiss="alert">&times;</button>
          <b><?= $_SESSION['response']; ?></b>
        </div>
        <?php } unset($_SESSION['response']); ?>
      </div>
    </div>
    <div class="row justify-content-center">
      <div class="col-md-5">
      <form action="action.php" method="post" enctype="multipart/form-data">
        <h3 class="text-center text-info"></h3>
          <input type="hidden" name="id" value="<?= $row['id']; ?>">

          <div class="">

        <h3>    <i class="bi bi-file-earmark-person-fill">Dane personalne </i></h3>
        
        
        </div>
          <div class="form-group form-inline justify-content-center">
            <textarea type="text" name="name_label" value="<?= $name_label; ?>" class="form-control mr-sm-2" placeholder="Imię i nazwisko" required>Imię i nazwisko</textarea>
        
            <textarea type="text" name="name"  class="form-control" placeholder="np Jan Kowalski" required><?= $row['name']; ?></textarea>
        
          </div>





          <div class="form-group form-inline justify-content-center">
            <textarea type="text" name="birth_label" value="<?= $birth_label; ?>" class="form-control mr-sm-2" placeholder="birth_label" required>Data urodzenia</textarea>
        
            <textarea type="text" name="birth" value="<?= $birth; ?>" class="form-control" placeholder="15-12-1992" required><?= $row['birth']; ?></textarea>
        
          </div>

        

Thank you for answer

  • 1
    You can put whatever HTML content you want on your page. It's not clear to me what exactly is stopping you or what isn't working as expected. Can you elaborate on the problem? – David Feb 15 '22 at 22:08
  • I have a form on a page in HTML, the form with the "select" command retrieves data from the database, when the "select" command does not receive data, the form does not appear on the page. – Mateusz Jankowski Feb 15 '22 at 22:13
  • The code shown has no form, no HTML at all. So, given only the code shown, I wouldn't expect any form to be rendered. Please provide a [mcve] and clarify the problem. – David Feb 15 '22 at 22:14
  • i change code in question – Mateusz Jankowski Feb 15 '22 at 22:19

0 Answers0