title: MySQL/PHP incorrect id displaying
body: <p>I am currently working on a school project and I need a little help. I am writing PHP/SQL code for a page where, when the user submits a form, a query runs that loops through and displays the user text input and also the value associated with the <code>&lt;select&gt;</code> dropdown.</p>
  
  <p>(For a visual idea of what I mean, visit <a href="http://themanaclub.com/themarketplace2/themarketplace2.php" rel="nofollow noreferrer">http://themanaclub.com/themarketplace2/themarketplace2.php</a>)</p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;?php
  include_once ('connection2.php');
  
  if (($_SERVER["REQUEST_METHOD"] == "POST") &amp;&amp; (isset($_POST['card_catalog_form']))) {
  
      $card_name = mysqli_real_escape_string($conn, $_POST['card_name']);
      $card_label = mysqli_real_escape_string($conn, $_POST['card_genre']);
      $insert_card_genre_query = sprintf("INSERT into card_catalog (card_name, label_id) VALUES ('%s', %u)",
          $card_name,
          $card_label);
      $insert_card_genre = mysqli_query($conn, $insert_card_genre_query) or die (mysqli_error($conn));
  
      $last_record = mysqli_insert_id($conn);
  }
  
  $card_genre_query = "SELECT card_genre.genre_id, card_label from `card_genre` order by genre_id desc";
  $card_genre = mysqli_query($conn, $card_genre_query) or die(mysqli_error($conn));
  
  $get_card_genre_query = "SELECT card_catalog.id, card_name, label_id, card_label from card_catalog left join card_genre on label_id = genre_id";
  $get_card_genre = mysqli_query($conn, $get_card_genre_query) or die(mysqli_error($conn));
  
  ?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;The Marketplace By The Mana Club&lt;/title&gt;
      &lt;link rel="stylesheet" type="text/css" href="stylesheets2/tmp2.css"&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
      &lt;?php include('templatestuff2/top_of_tmp2.php'); ?&gt;
  
      &lt;main&gt;
          &lt;h1&gt;Card Input Form:&lt;/h1&gt;
  
          &lt;form id="card_name_entry" action="&lt;?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?&gt;" method="post" enctype="multipart/form-data"&gt;
              &lt;h4&gt;What Card Are You Looking For?&lt;/h4&gt;
              &lt;textarea name="card_label" rows="5" cols="30" placeholder="Write the name of the card here"&gt;&lt;/textarea&gt;
              &lt;p&gt;
                  &lt;select name="card_genre"&gt;
                      &lt;?php while ($row_card_genre = mysqli_fetch_assoc($card_genre)) { ?&gt;
                      &lt;option value="&lt;?php echo $row_card_genre['genre_id'];?&gt;"&gt;&lt;?php echo $row_card_genre['card_label'];?&gt;&lt;?php echo $row_card_genre['card_name'];?&gt;&lt;/option&gt;
                      &lt;?php } ?&gt;
                  &lt;/select&gt;
              &lt;/p&gt;
  
              &lt;?php $query = "SELECT label_id from `card_catalog` right join `card_genre` on genre_id"; ?&gt;
  
              &lt;p id="textareasubmit"&gt;&lt;input type="submit"&gt;&lt;/p&gt;
              &lt;input type="hidden" name="card_catalog_form"&gt;
          &lt;/form&gt;
  
          &lt;section id="all_questions"&gt;
              &lt;ul&gt;
                  &lt;?php while ($row_card_genre = mysqli_fetch_assoc($get_card_genre)) { ?&gt;
                  &lt;li&gt;&lt;a href="otherphppages/card_detail.php?id=&lt;?php echo $row_card_genre['id'];?&gt;"&gt;&lt;?php echo $row_card_genre['card_label'];?&gt;&lt;/a&gt;&lt;/li&gt;
                  &lt;?php }
                      $row_card_genre = mysqli_data_seek($get_card_genre, 0);
                  ?&gt;
              &lt;/ul&gt;
          &lt;/section&gt;
  
          &lt;form action="&lt;?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?&gt;" method="post" enctype="multipart/form-data"&gt;
  
              &lt;p id="deletethissubmit"&gt;&lt;input type="submit" value="Delete This"&gt;&lt;/p&gt;
              &lt;input type="hidden" name="card_catalog_delete"&gt;
              &lt;input type="hidden" name="genre_id" value="&lt;?php echo $row_card_catalog['label_id'];?&gt;"
  
          &lt;/form&gt;
  
          &lt;p&gt;You're asking this at
              &lt;?php
                  date_default_timezone_set('America/New_York');
                  echo date('g:i a T \o\n l, F j, Y');
              ?&gt;
          &lt;/p&gt;
  
          &lt;p id="backtothemarketplace"&gt;&lt;a href="themarketplace2.php"&gt;Back To The Marketplace&lt;/a&gt;&lt;/p&gt;
  
          &lt;?php
  
          /*if (isset($_POST['card_genre'])) {
              $query = "SELECT card_catalog.card_name, card_catalog.label_id, card_genre.genre_id, card_genre.card_label FROM card_catalog, card_genre WHERE card_genre.genre_id = ?";
              $stmt = mysqli_prepare($conn, $query);
              $stmt-&gt;bind_param('s', $_POST['card_genre']);
              $stmt-&gt;execute();
              $result = $stmt-&gt;get_result();
  
              while ($row = $result-&gt;fetch_assoc()) {
                  echo $row['card_name']." - ".$row['label_id'];
                  echo "&lt;br /&gt;";
              }
          }*/
  
          ?&gt;
  
      &lt;/main&gt;
  
      &lt;?php include('templatestuff2/bottom_of_tmp2.php'); ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>If anybody has any help or constructive criticism, it would be greatly appreciated (I'm a PHP/SQL newbie so I'll take all the help that I can get).</p>
  
  <p>Thanks</p>