title: How can I send a row ID to a linked page using a submit button using HTML and PHP?
body: <p>The code below loops through a database table (accommodation) using mysqli_query and for each row creates a summary card to display an image and row info (name, ID, location, and price). 14 summary cards are displayed.</p>
  <p>A submit button links to a 'more info' page.</p>
  <pre><code>&lt;?php
      $query = &quot;SELECT * FROM accommodation&quot;;
      $result = mysqli_query($conn, $query);
      if ($result){
          if(mysqli_num_rows($result) &gt; 0){ 
              while($fetch = mysqli_fetch_assoc($result)){
                  ?&gt;                      
                  &lt;div class=&quot;summary-card&quot;&gt;      
                      &lt;img src=&quot;&lt;?php echo $fetch['main_image'] ?&gt;&quot; &gt;                  
                      &lt;p&gt; &lt;?php echo $fetch['name'], $fetch['ID'] ?&gt; &lt;/p&gt;
                      &lt;p&gt; &lt;?php echo $fetch['location'] ?&gt; &lt;/p&gt;
                      &lt;p&gt;from &lt;?php echo $fetch['price'] ?&gt; &lt;/p&gt;
                      &lt;form  action=&quot;info.php&quot; method=&quot;get&quot;&gt;
                          &lt;input type=&quot;submit&quot; name=&quot;&lt;?php echo $fetch['ID'] ?&gt;&quot; value=&quot;More info&quot; &gt;
                      &lt;/form&gt;
                  &lt;/div&gt;
                  &lt;?php
              }
          }
      }
  ?&gt;
  </code></pre>
  <p>Can accommodationID be sent when submitting?</p>
  <p>This would facilitate having <strong>just one</strong> 'more info' page and then being able to populate that page based on the table row ID that was passed when clicking on the related submit.</p>
  <p><strong>I've seen examples showing how to send a row ID to a linked page (<a href="https://stackoverflow.com/questions/43396371/pass-on-a-row-id-onto-another-page-in-php">1</a>, <a href="https://stackoverflow.com/questions/50314340/sending-rowid-through-a-form-to-another-php-using-a-button">2</a>, <a href="https://stackoverflow.com/questions/871858/php-pass-variable-to-next-page">3</a>) but not when the initial content was created using a loop.</strong></p>
  <p>So far I am able to append an ID to the target URL after clicking using the &quot;get&quot; method. However, if I try to print the ID using $_SESSION['accommodationID'] I get the ID relating to the last loop (14). If I use $_GET['accommodationID']I get an undefined index error.</p>
  <p>New to PHP (procedural) and have honestly done my best trying for a few days before posting.</p>