如果值不存在,则在3表中插入值;如果是ixist,则更新它

i have 3 table governorate district village and i want to be able to insert in each one of them values ... but i need to check first if the user input is not empty for the governorate field to be able to insert the district and to check if the user input for the district field is not empty to allow user to enter the village value with its coordinations ..

so i write this code but it do not work as i want can anyone help me ???to see where i did the mistake .

until now i just write the code for the village to add and for the governorate to remove

even if the values are inserted the system display the error msg :you must fill one of these fields befor you submit!!

code

 if(isset($_POST['add']))
   {
       if(isset($_POST['city']) || isset( $_POST['lat']) || isset($_POST['long']) == "" )
       {
         $errorMSG = "you must fill one of these fields befor you submit!!";
       }
      /* 
       if($_POST['gov'])
       {
           $gov = $_POST['gov'];
           $sql = mysql_query("INSERT INTO governorate (governorate_id, governorate_name)VALUES('', '$gov')")or die(mysql_error());
           echo $gov;
       }
       //******for adding district*********************
       elseif($_POST['dist'])
       {
           $dist = $_POST['dist'];
           $gov = $_POST['gov']; 
           if($gov)
           {
           $sql = mysql_query("INSERT INTO districts (district_id, district_name, governorate_id)VALUES('', '$dist', '$gov')")or die(mysql_error());

           $sql = mysql_query("INSERT INTO governorate (governorate_id, governorate_name)VALUES('', '$gov')") or die(mysql_error());

           echo $dist;
           }
           else{ $errorMSG = "You can not add District Without relate a Governorate for this district";}
       }
       */
       //********************for adding city****************************//

     if($_POST['city'])
       {
          $city = mysql_real_escape_string( $_POST['city']);
       $lat = mysql_real_escape_string($_POST['lat']);
       $long = mysql_real_escape_string($_POST['long']);
       $dist = mysql_real_escape_string($_POST['dist']); 
       $gov = mysql_real_escape_string( $_POST['gov']);
           if(!$dist)
           {
               $errorMSG = "you can not add city without having relation with district";
           }
           elseif($lat =="" || $long ==""){ $errorMSG = "You can not add village Without its coordinations";}
           else
           {
               $sqld = mysql_query("INSERT INTO districts (district_id, district_name, governorate_id)VALUES('', '$dist', '$gov')") or die(mysql_error());
           $sql = mysql_query("INSERT INTO village (id, village_name, district_id, lattitude, longitude)VALUES('', '$city', '$dist' ,'$lat',  '$long')")or die(mysql_error());

           }
       }

   }
/////******************for remove****************************************************//
/////********************************************************************************//
   if(isset($_POST['remove']))
   {
       if($_POST['gov'])
       {
           $gov = $_POST['gov'];
           $sql = mysql_query("DELETE FROM governorate WHERE governorate_name = '$gov'")or die(mysql_error());
       }
   } 

As far as your error message concerned '...even if the values are inserted the system display the error msg: you must fill one of these fields befor you submit!!...'

Your conditional is wrong. Change

if(isset($_POST['city']) || isset( $_POST['lat']) || isset($_POST['long']) == "" )

to

if ((!isset($_POST['city']) || $_POST['city'] == "") 
 && (!isset($_POST['lat'])  || $_POST['lat'] == "" )
 && (!isset($_POST['long']) || $_POST['long'] == "")) {

On a side note: your code is vulnerable to sql-injections. Switch to mysqli or PDO and learn prepared statements.