title: check mysql table data befor insert into
body: <p>I need to know if I can query and check database table data before the php scrip will INSERT INTO that table ?</p>
  
  <p>I have made an html with 2 fields and submit button(POST), and I also have no trouble with adding data to database table and getting its result, but I have duplicates and I don't want to have it ... I want script to check my data , the entering data and if no duplicate then add it.</p>
  
  <p>Please assist.</p>
  
  <p>Thank you</p>
  
  <p>Code</p>
  
  <pre><code>&lt;?php
  
  
  $con=mysqli_connect("localhost","root","Opera1","railway");
  
  
  if(mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: ", mysqli_connect_error;
  }
  
  $data1 = $_POST['data1'];
  $data2 = $_POST['data2'];
  
  
  
  $sql="replace into pipe (data1, data2) 
  values ('$data1','$data2')";
  
  
  
  if(!mysqli_query($con,$sql))
  {
  die('Error : ' . mysqli_error($con));
  }
  
  
  echo "Record to Registraton added";
  
  $result = mysqli_query($con,"SELECT * FROM pipe");
  
  echo "&lt;table border='1'&gt;
  &lt;tr&gt;
  &lt;th&gt;Data1&lt;/th&gt;
  &lt;th&gt;Data2&lt;/th&gt;
  &lt;/tr&gt;";
  
  while($row = mysqli_fetch_array($result))
    {
   echo "&lt;tr&gt;";
    echo "&lt;td&gt;" . $row['data1'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['data2'] . "&lt;/td&gt;";
    echo "&lt;/tr&gt;";
    }
  echo "&lt;/table&gt;&lt;br&gt;&lt;br&gt;";
  
  
  mysqli_close($con);
  
  
  ?&gt;
  </code></pre>