title: check through second column by first column id
body: <p>I have 2 columns under sales table in SQL as below</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>id</th>
  <th>itemid</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>31</td>
  </tr>
  <tr>
  <td>1</td>
  <td>32</td>
  </tr>
  <tr>
  <td>1</td>
  <td>33</td>
  </tr>
  <tr>
  <td>1</td>
  <td>34</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I need through the PHP to check by the id, if the $_SESSION['id'] has any item number in the second column then tell the user that the item already exists, otherwise add this item to DB ..
  I did do fat the below code but it doesn't work, it will print both conditions if statement</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;?php
  
  session_start();
  include "connect.php";
  $access = isset($_SESSION["userid"]);
  if ($access) {
      
      $itemid = filter_input(INPUT_GET, "itemid", FILTER_VALIDATE_INT);
  
      if($itemid !== null &amp;&amp; $itemid !== false){
          $SQL = $dbh-&gt;prepare("SELECT * FROM sales where userid = ?");
          if($SQL-&gt;execute([$_SESSION["userid"]])){
              if ($SQL-&gt;rowCount() &gt; 0){
                  while($row = $SQL-&gt;fetch()){
                      if((int)$row['itemid'] === $itemid){
                          echo "item is exist";
                      }else{
                          echo "add it to the table";
                      }                   
                  }
              }
          }
      }
  }</code></pre>
  </div>
  </div>
  </p>