如何阻止使用相同的信息创建相同的用户?

How do I check if the user already created the same LRN ? and when I press the save button twice it creates two user with the same info
how do I prevent it ?

jQuery('#save_voter').submit(function(e){
e.preventDefault();
var FirstName = jQuery('.FirstName').val();
var LastName = jQuery('.LastName').val();
var Section = jQuery('.Section').val();
var Year = jQuery('.Year').val();
var LRN = jQuery('.LRN').val();
var Password = jQuery('.Password').val();

e.preventDefault();
if (FirstName && LastName && Section && Year && LRN && Password){   
var formData = jQuery(this).serialize();    

jQuery.ajax({
    type: 'POST',
    url:  'save_student.php',
    data: formData,
         success: function(msg){
        showNotification({
message: "Student Successfully Added",
type: "success", 
autoClose: true, 
duration: 5 

});

By creating a unique constraint on the username field. It seems that in your case the LRN field is the username field. Make it unique by

ALTER TABLE users ADD UNIQUE INDEX uname on users (LRN);

Then you can try something like this to tell the end user that the username is duplicated.

try{
   $res =$connection->query(your user insert);
}catch(Exception $e){
   echo 'Sorry already exists';
}

You need to do 3 steps :

  • Check manually First Name and Last Name already exists or not in PHP file
  • In resultset contains more than 0 records, then return false which means record already exists.
  • In JQuery, if its getting false, then show an error message that record already exists.

Further, as @kongkang said in comments that the field LRN is as username.

then still you need to do 3 steps :

  • Make that field as unique in database table
  • Add if condition on insertion query (PHP File) that if return false it means record already exists
  • in Jquery, if returning value is false, then show error message.

Add a unique index to your database for a unique field.I hope LRN is there for you. Then

MYSQL:
ALTER TABLE users ADD UNIQUE (LRN)
SQL SERVER: 
ALTER TABLE [users] ADD CONSTRAINT UC_LRN UNIQUE ([LRN]);

When you try to insert duplicate LRN database error will come automatically for Codeigniter. Without it you have to check manually.