检查php / mysql中的多个重复值验证错误

I am trying to insert a form value into database with several compulsory field ,But before inserting I am wanted to check if any of same value is already exist in database.for this my code is

<?php include_once 'header.php';$flag=0;
if(isset($_POST['submit']))
 {  $eid =$_POST["eid"];
   if($eid=="blank") {$flag=1;
  $idErr="please Select E-MITRA";}
  else{
  $sqli="SELECT * FROM emitra_device where uid='$eid'";
  $result1 = $conn->query($sqli);
$rowe=mysqli_fetch_array($result1);
if($rowe!=""){ $flag=1;
$idErr=" User ID Already Entered";} }

$miatm =trim($_POST["miatm"]);
 if(empty($miatm) || !preg_match("/^[a-zA-Z0-9 ]*$/",$miatm)) {$flag=1; 
$miErr="Please Enter Valid  Id"; }
 else{$sqlm="SELECT * FROM emitra_device where m_sno='$miatm'";
  $resultm = $conn->query($sqlm);
$rowm=mysqli_fetch_array($resultm);
if($rowm!="")
{$flag=1;$miErr=" machine ID Already Entered";}}   

.........and some for 3 more field

//for insertion

 if($flag==0){$sqll="insert into *********** "}}?>
   working well

// form coding like is...

<form id="basic" method="post" name="basic"> 
<select class="select-style gender" name="eid">
<option value="blank">Please Select E-MITRA ID</option> 
 <option value="****">*****</option></select>
  <?php echo $idErr;?>

<p class="contact"><label for="bid">m/s Serial No</label></p> 
<input type="text" name="miatm" value ="<?php if (isset($miatm)) echo $miatm; ?>"/> <?php echo $miErr; ?>

 ........more

its working well, but i know it could be improved . Its may be like this

$dupesql = "SELECT * FROM table where (uid= '$eid' OR ***= '$miatm' OR **= '$**')";

  $duperaw = mysql_query($dupesql);
 if (mysql_num_rows($duberaw) > 0) {.....  }

But in this I cannot show to user what he enter duplicate....ID/Mno/etc. Please Suggest a Better Way

You can still show to user what he entered duplicate. Here is the way:

You don't need to select all filed from table. Just select those 5 field, on which you want to have duplicate check.

Once you have result, you foreach/for loop to check which column meets the user entered value. Whichever meets, that's already entered.

$error_array = array();
foreach($duperaw as $this_row)
{
    if($this_row['uid'] == $eid) 
        $error_array[] = 'User ID Already Entered';

    if($this_row['m_sno'] == $miatm) 
        $error_array[] = 'Machine ID Already Entered';
    .. .. ..
}

Then show the full array with errors.