php - Help with logic -


i have created 1 field unique in database. consider album name unique. have added constraints if user try add other album name error message record present. user may not add other record same name.

but have problem if 3 records exists in database name a,b,c. , user updating of field can update record b name of a 2 records in database a. & want create unique. using script..

if($name!="") {   $sql = "select a_name t_a_list a_name = '$name'";   $result = mysql_query($sql);    if(mysql_num_rows($result) != 0) {     $msg = "<font color=red>record not saved. album exist!</font>";   } } else {   $msg = "<font color=red>enter name of album!</font>"; }  if($msg=="") { //update query } 

but have problem each pageload updation need choose different name album. because show album exist msg. might possible want change rest of information other name of album year of release, total track. script if want update rst of field need change album name first. please problem. album name may not repeat in db , can update other information other name.

you save oldname in variable , when updating first check

if($name!=$oldname) { ... 
. way won't update name unless changed , updates other fields made
 $oldname = the name of album being edited .... if($name!=$oldname) {  if($name!="") {  $sql = "select a_name t_a_list a_name = '$name'";  $result = mysql_query($sql);  if(mysql_num_rows($result) != 0) {      $msg = "record not saved. album exist!";  }  } else {  $msg = "enter name of album!";  }  if($msg=="") {  //update query  } } if($description!="") { .... } if($location!="") { ... } ... 


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -