php - How to detect that username already use in the database -


<?php  if(isset($_post["add"]))     {  $name=$_post["emp_username"]; $pass=$_post["emp_password"]; $fname=$_post["emp_fname"]; $lname=$_post["emp_lname"]; $hph=$_post["contactno_home"]; $hp=$_post["contactno_hp"]; $mail=$_post["emp_email"]; $add=$_post["emp_address"]; $age=$_post["emp_age"]; $pos=$_post["position"]; $dept=$_post["dept_id"];  mysql_query("     insert employee(dept_id, emp_address, emp_age,      position, >emp_username, emp_password, emp_fname, emp_lname,      contactno_home, contactno_hp, emp_email)      >values('$dept','$add','$age','$pos','$name','$pass','$fname',     '$lname','$hph','$hp','$mail'>)    ");  ?>      <script type="text/javascript"> alert("record saved.");     </script>   <?php } ?> 

create unique key on username field, detect error no 1062:

if (mysql_errno() == 1062) {     print 'username taken!'; } 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -