title: If else query, so the user cannot input higher than the quantity left
body: <p>Additional if else query so that the user cant input higher than the stock.</p>
  
  <p>I want to add an if else query where in the user cannot input higher than the stocks , what would be the best approach.</p>
  
  <p>This is my code</p>
  
  <pre><code>&lt;?php
  
      include('session.php');
      if(isset($_POST['cart'])){
          $id=$_POST['id'];
          $qty=$_POST['qty'];
  
          $query=mysqli_query($conn,"select * from cart where productid='$id' and userid='".$_SESSION['id']."'");
          if (mysqli_num_rows($query)&gt;0){
              echo "Product already on your cart!";
          }   
          else{
              mysqli_query($conn,"insert into cart (userid, productid, qty) values ('".$_SESSION['id']."', '$id', '$qty')");
          }
      }
  
  ?&gt;
  </code></pre>
  
  <p>Thanks.</p>