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 :
record already exists
.Further, as @kongkang said in comments that the field LRN is as username.
then still you need to do 3 steps :
unique
in database tableAdd 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.