title: Error messages with different situations while saving to database with php form
body: <p>i have a script that saves records to mysql with no problem. but i want to add some code to show an error message if the name or code already exists in the database. the code is like below;</p>
  
  <pre><code>&lt;?php
  
  $urunadi        = $_POST["urunadi"];
  $malzemekodu    = $_POST["malzemekodu"];
  $urunkategorisi = $_POST["urunkategorisi"];
  $birim          = $_POST["birim"];
  $miktar         = $_POST["miktar"];
  $personel       = $_POST["personel"];
  $birimfiyat     = $_POST["birimfiyat"];
  $toplamfiyat    = $_POST["birimfiyat"]*$_POST["miktar"];
  $fiyatbirimi    = $_POST["fiyatbirimi"];
  
  
  if(empty($urunadi)){
  echo("&lt;center&gt;&lt;b&gt;Product name empty, please go back and fill this line.&lt;/b&gt;&lt;/center&gt;");
  }else
  if(empty($miktar)){
  echo("&lt;center&gt;&lt;b&gt;Product amount empty, please go back and fill this line.
  }else
  if(empty($malzemekodu)){
  echo("&lt;center&gt;&lt;b&gt;Product code empty, please go back and fill this line.&lt;/b&gt;&lt;/center&gt;");
  }else
  if(empty($birimfiyat)){
  echo("&lt;center&gt;&lt;b&gt;Unit price empty, please go back and fill this line.&lt;/b&gt;&lt;/center&gt;");
  }else{
  include "database.php";
  $sql = (" insert into `depo` (`urunadi`,`malzemekodu`,`urunkategorisi`,`birim`,`miktar`,`personel`,`birimfiyat`,`toplamfiyat`,`fiyatbirimi`)
  VALUES ('$urunadi','$malzemekodu','$urunkategorisi','$birim','$miktar','$personel','$birimfiyat','$toplamfiyat','$fiyatbirimi');");
  $kayit = mysql_query($sql);
  }
  if (isset ($kayit)){
  echo "&lt;center&gt;Data saved&lt;/center&gt;";
  }
  else {
  echo "&lt;center&gt;Data could not be saved&lt;/center&gt;";
  }
  if (isset($_REQUEST["kullanici"])) {
  include("database.php");
  $sql = ("select * from uye");
  }
  else {
  header ("Location: uyari.html");
  }
  ?&gt;
  </code></pre>