php - if/else for non-duplicate of data -


im having problem, seems codes incorrect. want prevent duplication of data. in array submit form result, if user have kind of row, can insert data not in table. current code not insert data. if remove if else statements, data within loop can inserted.

    if(isset($_post['submit']))     {         $var_emp_id = $_post["emp_id"];         $var_task_id = $_post["task_id"];         $var_weight = $_post['weight'];         $submit=$_post['submit'];          ($i = 0; $i <= count($var_emp_id); $i++)         {             $sql=mysql_query("select emp_id,task_id peval_tbl emp_id = '$var_emp_id[$i]' , task_id = '$task_id[$i]'");              while($row=mysql_fetch_assoc($sql))             {                  $emp_id = $row['emp_id'];                 $task_id = $row['task_id'];                  if ($var_emp_id[$i] ==  $emp_id && $var_task_id[$i] == $task_id){                 mysql_query("insert ignore peval_tbl(weight,task_id,emp_id)                         values('$var_weight[$i]','$var_task_id[$i]','$var_emp_id[$i]')");                                                }         else{                error_reporting(e_all ^ e_notice);              ($i = 0; $i <= count($var_emp_id); $i++)         {         mysql_query("insert peval_tbl(weight,task_id,emp_id)                         values('$var_weight[$i]','$var_task_id[$i]','$var_emp_id[$i]')");          }         }         }     }     } 

i suggest putting primary key on table on column(s) unique, using insert ignore query load (ignore doesn't throw error on duplicates).


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -