Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

PHP posting chosen option to another page

220061

Well-Known Coder
I'm not seeing what I'm doing wrong. so basically what I want is that users click the button and then the $row['name'] will be posted to another page. but for some reason I just can't get it to work?? can someone help me ?
PHP:
    <?php
      $sql = "SELECT * FROM huizen";
      $stmt = $conn->prepare($sql);
      $stmt->execute();
      $result = $stmt->get_result();
      while ($row = mysqli_fetch_assoc($result)) {
          echo '       
          <div class="product">
          <form action="../reservation.php" method="POST">
            <h3 class="productname" id="naam" name="naam">'.$row['naam'].'</h3>
            <img src="../'.$row['img_dir'].'" alt="huis" style="width: 100%; height: 50%;">
              <p>'.$row['beschrijving'].'</p>
              <p class="price">'.$row['price'].'</p>
              <button class="addtocart" name="bestellen">Bestellen</button>
            </form>
          </div>';
      }
      ?>

this is the other page I want to show the naam from the first page ? what is going wrong?
Code:
 <h2>Reserveren <?php $_POST['naam'];?>
 
You need to have an actual form field to submit with your form. Change:

PHP:
<h3 class="productname" id="naam" name="naam">'.$row['naam'].'</h3>

To:

Code:
<label>
    '.$row['naam'].'
    <input type="hidden" name="naam" value="'.$row['naam'].'" />
</label>

Also, you need to echo out the value when you retrieve it if you want to display it, so:

Code:
<h2>Reserveren <?php echo $_POST['naam'];?>
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom