I have no idea how to block users from creating account if the username is already taken.. Can someone help me.. I try looking scripts or tutorial on the internet but they're no good.. I'm just a noobie in coding.. my table is called "user_acc" and the username field is "username"
here's my ajax script
function validateEmail(str){
var testresults;
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
//var filter1=/^[A-Za-z]+$/;
if (filter.test(str))
testresults=true;
else
testresults=false
return (testresults)
}
//registration
$(document).ready(function(){
$('#submbut').click(function(){
var fn = $('#fnamae').val();
var ln = $('#lnamae').val();
var un = $('#unamae').val();
var pass = $('#pass').val();
var pass2 = $('#pass2').val();
var mail = $('#mail').val();
var cont = $('#cont').val();
var url = "http://localhost/picturecity/acceptusr";
if(fn == "" && ln == "" && un == "" && pass == "" && pass2 == "" && mail == "" && cont == "" || fn == "" || ln == "" || un == "" || pass == ""
|| pass2 == "" || mail == "" || cont == ""){
alert('Error: Fill up all fields');
}
else{
if(pass == pass2)
{
if(validateEmail(mail)){
$.ajax({
url:url,
data: "fn="+fn+"&ln="+ln+"&un="+un+"&pass="+pass+"&mail="+mail+"&cont="+cont,
type:"post",
success:function(e){
alert('Registration Successful');
}//success
});//ajax
}
else{
alert("Invalid Email Format");
}
}//if
else{
alert('Password Do Not Match');
}
}
});//click
}); //document
my controller code for registration
public function acceptusr(){
$data = array (
"firstname"=>$this->input->post('fn'),
"lastname"=>$this->input->post('ln'),
"username"=>$this->input->post('un'),
"password"=>md5($this->input->post('pass')),
"email"=>$this->input->post('mail'),
"contact"=>$this->input->post('cont')
);
$this->Mod_admin->addtotb('user_acc',$data);
}
the model
public function addtotb($table, $data)
{
$this->db->insert($table,$data);
}
please help me how to create username validation thanks..