title: Check if query was successful
body: <p>Lets say I have a <strong>categories table</strong> and then I have <strong>products table</strong>. </p>
  
  <p>Each product belongs to some category. </p>
  
  <p>Now, I want to remove a category which is assigned to some products.</p>
  
  <p>This will cause an error, because I can not remove something from database because of database relations. My code below removes a row from a table (using jquery) but it removes the category for real only if it no product is using it.</p>
  
  <p>I am trying to create some error warning when I click on <code>Delete</code> icon and the category can not be removed. How can I do that? I would prefer some jQuery popup window with the warning, but I don't really know how should I check for the error in the first place.</p>
  
  <p><strong>EDIT:</strong>
  I have tried to use <code>echo 1;</code> and <code>echo 0;</code> as <code>response</code> for <code>ajax</code> but I am getting the warning message every time I want to remove something, even if there is no error.</p>
  
  <pre><code>&lt;tbody&gt;
     &lt;?php
     $cat_list = "SELECT * FROM games_category";
     $result = mysqli_query($conn, $cat_list);
     while($row = mysqli_fetch_assoc($result)) {
         $id = $row['id'];
         $name = $row['name'];
         ?&gt;
         &lt;tr&gt;
             &lt;td&gt;&lt;?php echo $id; ?&gt;&lt;/td&gt;
             &lt;td&gt;&lt;?php echo $name; ?&gt;&lt;/td&gt;
             &lt;td&gt;
                 &lt;span class='delete_game_cat' id='del_&lt;?php echo $id; ?&gt;'&gt;&lt;img src="../images/remove.png" alt="" title="Delete" class="icon"/&gt;&lt;/span&gt;
             &lt;/td&gt;
         &lt;/tr&gt;
         &lt;?php
     }
     ?&gt;
  &lt;/tbody&gt;
  </code></pre>
  
  <p>Here is script:</p>
  
  <pre><code>$(document).ready(function(){
     // Delete
     $('.delete_game_cat').click(function(){
         var el = this;
         var id = this.id;
         var splitid = id.split("_");
  
         // Delete id
         var deleteid = splitid[1];
  
         // AJAX Request
         $.ajax({
             url: 'delete_game_cat.php',
             type: 'POST',
             data: { id:deleteid },
             success: function(response){
                  if(response===1){
                     // Removing row from HTML Table
                     $(el).closest('tr').css('background','tomato');
                     $(el).closest('tr').fadeOut(600, function(){
                         $(this).remove();
                     });
                  }else{
                      alert("This category cannot be deleted!");
                  }
             }
         });
     });
  });
  </code></pre>
  
  <p>And sql query:</p>
  
  <pre><code>$id = $_POST['id'];
  $query = "DELETE FROM games_category WHERE id =".$id;
  
  if(mysqli_query($conn, $query)){
      echo 1;
  }else{
      echo 0;
  }
  </code></pre>