title: Checking if a particular entry already present in MySQL
body: <p>I've a table <code>events</code> with the following fields:</p>
  
  <pre><code>`id`--&gt;INT,PRIMARY AND AUTO_INCREMENT
  `event_id`--&gt;INT
  `mem_1_id`--&gt;INT
  `mem_2_id`--&gt;INT
  `mem_3_id`--&gt;INT
  `mem_4_id`--&gt;INT
  `mem_5_id`--&gt;INT
  `mem_6_id`--&gt;INT
  </code></pre>
  
  <p>All the <code>mem_x_id</code> <code>(0&lt;x&lt;7)</code> will be distinct for a particular <code>event_id</code> in <code>events</code> TABLE.
  The <code>id</code> is the primary key that is normally used. A Possible example:</p>
  
  <pre><code>id  event_id    mem_1_id    mem_2_id    mem_3_id    mem_4_id    mem_5_id    mem_6_id
  1   11          123         345         567         67          34          56
  2   12          234         555         67          43          23          12
  2   12          34          55          167         435         233         122
  </code></pre>
  
  <p>Now I want to check if the user's <code>id</code> (From  the <code>users</code> TABLE) who has logged in and is viewing the page of a particular event is present or not in <code>events</code> TABLE under that event's <code>id</code>. There may be multiple entries for a particular <code>event_id</code>
  . I want to search in all those <code>event_id</code> that are of the event page.</p>
  
  <p>My code is below: Please note, I'm new to PHP and hence still using the old version. I plan to get things working, and then modify my code to PDO. I'm learning PDO parallelly. But first I wish to make my code work.</p>
  
  <pre><code>$id=stores the event_id of the event page that the user is viewing.
  
  $_SESSION['id']=`id` of the user that is logged in and viewing the page.
  
  if(isset($_SESSION['id'])){
      $result1=mysql_query("SELECT id FROM events WHERE event_id='".$id."')");
          if ($result1 == false) {
              echo mysql_error();
              die;
          }
          $row1 = mysql_fetch_assoc($result1);
  
          if($row1['id']){
              if ($_SESSION['id']==$row1['mem_1_id'] || $_SESSION['id']==$row1['mem_2_id'] || $_SESSION['id']==$row1['mem_3_id'] || $_SESSION['id']==$row1['mem_4_id'] || $_SESSION['id']==$row1['mem_5_id'] || $_SESSION['id']==$row1['mem_6_id']){
                  $is_already_regis=1;
              }
          }
      }
  </code></pre>