title: PHP check if unique
body: <p>I have this code to enter product in my stoc administration script.
  I need some help.
  I want when i enter new product to check if row cod (codint in mysql ) is unique and if is not unique alert me.</p>
  
  <p>Like opencat model field .. </p>
  
  <pre><code>&lt;?php 
  require('header.php'); 
  include('functii/functions.php');
  if(isset($_POST[submit]) &amp;&amp; !empty($_POST[nume])){
      $_POST[nume] = mysql_real_escape_string($_POST[nume]);
      $_POST[stoc] = mysql_real_escape_string($_POST[stoc]);
      $_POST[pretintrare] = mysql_real_escape_string($_POST[pretintrare]);
      $_POST[pretrecomandat] = mysql_real_escape_string($_POST[pretrecomandat]);
      $_POST[comentarii] = mysql_real_escape_string($_POST[comentarii]);
      $_POST[descriere] = mysql_real_escape_string($_POST[descriere]);
      $_POST[locatie] = mysql_real_escape_string($_POST[locatie]);
      $_POST[stare] = mysql_real_escape_string($_POST[stare]);
      $_POST[tip] = mysql_real_escape_string($_POST[tip]);
      $sql = "INSERT INTO stoc (nume, tip, locatie, stoc, pretintrare, pretrecomandat, stare, comentarii, descriere, model1, model2, model3, model4, model5, model6, model7, model8, model9, model10, model11, model12, model13, model14, brand, img, img2, img3, img4, codint) VALUES ('$_POST[nume]', '$_POST[tip]', '$_POST[locatie]', '$_POST[stoc]', '$_POST[pretintrare]', '$_POST[pretrecomandat]', '$_POST[stare]', '$_POST[comentarii]', '$_POST[descriere]', '$_POST[model1]', '$_POST[model2]', '$_POST[model3]', '$_POST[model4]', '$_POST[model5]', '$_POST[model6]', '$_POST[model7]', '$_POST[model8]', '$_POST[model9]', '$_POST[model10]', '$_POST[model11]', '$_POST[model12]', '$_POST[model13]', '$_POST[model14]', '$_POST[brand]', '$_POST[img]', '$_POST[img2]', '$_POST[img3]', '$_POST[img4]', '$_POST[codint]' )";
      $result=mysql_query($sql);  
      $last_id=mysql_insert_id(); 
      die('&lt;script type="text/javascript"&gt;window.location.href="stoc-id.php?id='.$last_id.'";&lt;/script&gt;');
  }
  ?&gt;  
  
      &lt;ul id="nav"&gt;
          &lt;li class="inactive"&gt;&lt;a href="stoc.php?t=ecran"&gt;Ecrane&lt;/a&gt;&lt;/li&gt;
          &lt;li class="inactive"&gt;&lt;a href="stoc.php?t=tastatura"&gt;Tastaturi&lt;/a&gt;&lt;/li&gt;
          &lt;li class="inactive"&gt;&lt;a href="stoc.php?t=incarcator"&gt;Incarcatoare&lt;/a&gt;&lt;/li&gt;
          &lt;li class="inactive"&gt;&lt;a href="stoc.php?t=hdd"&gt;HDD&lt;/a&gt;&lt;/li&gt;
          &lt;li class="inactive"&gt;&lt;a href="stoc.php?t=placibaza"&gt;Placi de baza&lt;/a&gt;&lt;/li&gt;
          &lt;li class="inactive"&gt;&lt;a href="stoc.php?t=ram"&gt;RAM&lt;/a&gt;&lt;/li&gt;
          &lt;li class="inactive"&gt;&lt;a href="stoc.php?t=Cooler"&gt;Cooler&lt;/a&gt;&lt;/li&gt;
          &lt;li class="inactive"&gt;&lt;a href="stoc.php?t=balamale"&gt;Balamale&lt;/a&gt;&lt;/li&gt;
          &lt;li class="inactive"&gt;&lt;a href="stoc.php?t=laptop"&gt;Laptop&lt;/a&gt;&lt;/li&gt;
          &lt;li class="inactive"&gt;&lt;a href="stoc.php?t=accesoriil"&gt;Accesorii Laptop&lt;/a&gt;&lt;/li&gt;
          &lt;li class="inactive"&gt;&lt;a href="stoc.php?t=mufealimentare"&gt;Mufe Alimentare&lt;/a&gt;&lt;/li&gt;
          &lt;li class="inactive"&gt;&lt;a href="stoc.php?t=moduleel"&gt;Module Electronice&lt;/a&gt;&lt;/li&gt;
          &lt;li class="inactive"&gt;&lt;a href="stoc.php?t=carcasa"&gt;Carcasa laptop&lt;/a&gt;&lt;/li&gt;
          &lt;li class="inactive"&gt;&lt;a href="stoc.php?t=dez"&gt;Dezmembrari&lt;/a&gt;&lt;/li&gt;      
      &lt;/ul&gt;
  
      &lt;div id="content"&gt;
          &lt;h1&gt;Adauga un produs pe stoc:&lt;/h1&gt;          
          &lt;form action="stoc-adauga.php" method="post"&gt;
  
              &lt;div id="tichetleft"&gt;               
                  &lt;p&gt;Nume: &lt;input style="margin-left: 40px;" type="text" name="nume"&gt;&lt;/p&gt;
                  &lt;p&gt;Cod: &lt;input style="margin-left: 52px;" type="text" name="codint"&gt;&lt;/p&gt;
                  &lt;p&gt;Stoc: &lt;input style="margin-left: 51px;" type="text" name="stoc"/&gt;&lt;/p&gt;
                  &lt;p&gt;Pret recom: &lt;input style="margin-left: -1px;" type="text" name="pretintrare"/&gt;&lt;/p&gt;               
              &lt;/div&gt;
  
              &lt;div id="tichetright"&gt;              
                  &lt;p&gt;Locatie:
                  &lt;input style="margin-left: 33px;" type="radio" id="1" name="locatie" value="0"&gt;&lt;label for="1"&gt;Crangasi&lt;/label&gt;
                  &lt;input type="radio" name="locatie" id="2" value="1" checked="checked"&gt;&lt;label for="2"&gt;Dristor&lt;/label&gt;
                  &lt;/p&gt;
                  &lt;p style="margin-top: 27px;"&gt;Stare: 
                  &lt;input style="margin-left: 48px;" id="3" type="radio" name="stare" value="0" checked="checked"&gt;&lt;label for="3"&gt;Nou&lt;/label&gt;
                  &lt;input type="radio" name="stare" id="4" value="1"&gt;&lt;label for="4"&gt;Second-Hand&lt;/label&gt;
                  &lt;/p&gt;
                  &lt;p style="margin-top: 23px;"&gt;Pret Distributie: &lt;input style="margin-left: 13px;width:262px;" type="text" name="pretrecomandat"/&gt;&lt;/p&gt;
              &lt;/div&gt;
  
              &lt;div class="clear"&gt;&lt;/div&gt;
  
              &lt;div id="center"&gt;
                  &lt;p class="stoc"&gt;Tip:
                  &lt;input type="radio" id="5" name="tip" value="ecran" checked="checked"&gt;&lt;label for="5"&gt;Ecran&lt;/label&gt;
                  &lt;input type="radio" id="6" name="tip" value="tastatura"&gt;&lt;label for="6"&gt;Tastatura&lt;/label&gt;
                  &lt;input type="radio" id="7" name="tip" value="incarcator"&gt;&lt;label for="7"&gt;Incarcator&lt;/label&gt;
                  &lt;input type="radio" id="8" name="tip" value="hdd"&gt;&lt;label for="8"&gt;HDD&lt;/label&gt;
                  &lt;input type="radio" id="9" name="tip" value="placibaza"&gt;&lt;label for="9"&gt;Placa de baza&lt;/label&gt;
                  &lt;input type="radio" id="10" name="tip" value="ram"&gt;&lt;label for="10"&gt;RAM&lt;/label&gt;
                  &lt;input type="radio" id="12" name="tip" value="cooler"&gt;&lt;label for="12"&gt;Cooler&lt;/label&gt;
                  &lt;input type="radio" id="13" name="tip" value="balamale"&gt;&lt;label for="13"&gt;Balamale&lt;/label&gt;
                  &lt;input type="radio" id="11" name="tip" value="laptop"&gt;&lt;label for="11"&gt;Laptop&lt;/label&gt;
                  &lt;input type="radio" id="14" name="tip" value="accesoriil"&gt;&lt;label for="14"&gt;Accesorii Laptop&lt;/label&gt;
                  &lt;input type="radio" id="15" name="tip" value="mufealimentare"&gt;&lt;label for="15"&gt;Mufe Alimentare&lt;/label&gt;
                  &lt;input type="radio" id="16" name="tip" value="moduleel"&gt;&lt;label for="16"&gt;Module Electronice&lt;/label&gt;
                  &lt;input type="radio" id="17" name="tip" value="carcasa"&gt;&lt;label for="17"&gt;Carcasa&lt;/label&gt;
                  &lt;input type="radio" id="18" name="tip" value="dez"&gt;&lt;label for="18"&gt;Dezmembrari&lt;/label&gt;
                  &lt;/p&gt;
                  &lt;p&gt;Note int: &lt;textarea style="margin-left: 45px;" type="text" name="comentarii"/&gt;&lt;/textarea&gt;&lt;/p&gt;
                  &lt;p&gt;Descriere: &lt;textarea style="margin-left: 45px;" type="text" name="descriere"/&gt;&lt;/textarea&gt;&lt;/p&gt;
              &lt;/div&gt;
              &lt;div id="tichetleft"&gt;   
              &lt;p&gt;Model1: &lt;input style="margin-left: 40px;" type="text" name="model1"&gt;&lt;/p&gt;
              &lt;p&gt;Model2: &lt;input style="margin-left: 40px;" type="text" name="model2"&gt;&lt;/p&gt;
              &lt;p&gt;Model3: &lt;input style="margin-left: 40px;" type="text" name="model3"&gt;&lt;/p&gt;
              &lt;p&gt;Model4: &lt;input style="margin-left: 40px;" type="text" name="model4"&gt;&lt;/p&gt;
              &lt;p&gt;Model5: &lt;input style="margin-left: 40px;" type="text" name="model5"&gt;&lt;/p&gt;
              &lt;p&gt;Model5: &lt;input style="margin-left: 40px;" type="text" name="model11"&gt;&lt;/p&gt;
              &lt;p&gt;Model5: &lt;input style="margin-left: 40px;" type="text" name="model12"&gt;&lt;/p&gt;
              &lt;p&gt;Brand: &lt;input style="margin-left: 40px;" type="text" name="brand"&gt;&lt;/p&gt;
              &lt;p&gt;IMG3: &lt;input style="margin-left: 40px;" type="text" name="img3"&gt;&lt;/p&gt;
              &lt;/div&gt;
              &lt;div id="tichetright"&gt;
              &lt;p&gt;Model6: &lt;input style="margin-left: 40px;" type="text" name="model6"&gt;&lt;/p&gt;
              &lt;p&gt;Model7: &lt;input style="margin-left: 40px;" type="text" name="model7"&gt;&lt;/p&gt;
              &lt;p&gt;Model8: &lt;input style="margin-left: 40px;" type="text" name="model8"&gt;&lt;/p&gt;
              &lt;p&gt;Model9: &lt;input style="margin-left: 40px;" type="text" name="model9"&gt;&lt;/p&gt;
              &lt;p&gt;Model0: &lt;input style="margin-left: 40px;" type="text" name="model10"&gt;&lt;/p&gt;
              &lt;p&gt;Model0: &lt;input style="margin-left: 40px;" type="text" name="model13"&gt;&lt;/p&gt;
              &lt;p&gt;Model0: &lt;input style="margin-left: 40px;" type="text" name="model14"&gt;&lt;/p&gt;            
              &lt;p&gt;IMG: &lt;input style="margin-left: 40px;" type="text" name="img"&gt;&lt;/p&gt;
              &lt;p&gt;IMG2: &lt;input style="margin-left: 40px;" type="text" name="img2"&gt;&lt;/p&gt;
              &lt;p&gt;IMG4: &lt;input style="margin-left: 40px;" type="text" name="img4"&gt;&lt;/p&gt;
              &lt;/div&gt;
              &lt;div id="center"&gt;               
                  &lt;input type="submit" style="padding-left: 25px;" name="submit" value="Adauga produsul"&gt;&lt;img style="vertical-align: -10%;margin-left:-160px;" src="imagini/produs-icon.png" alt="Adauga tichet"&gt;&lt;/input&gt;
              &lt;/div&gt;
  
          &lt;/form&gt;
  
      &lt;/div&gt; &lt;!-- end content --&gt;
  
  &lt;?php require('footer.php');?&gt;
  </code></pre>