I have a codeigniter application.This is my code in view page.
function click_next(){
var aname = $("#txtuname").val();
var apasswd = $("#txtupass").val();
if(aname == ''){
$("#error_val").css("display","block")
$("#error_val").html("user name required");
});
}else if(apasswd == ''){
$("#error_val").css("display","block")
$("#error_val").html("password required");
}else{
var cnt=$("#alogin").serialize();
$.ajax({
type: "POST",
url: "<?php echo base_url();?>index.php/admin/adminLogin/",
data: cnt,
success: function(msg){
if(msg==1){
window.location="<?php echo base_url();?>index.php/admin/adminHome/";
}
else{
$("#error_val").css("display","block")
$("#error_val").html(msg);
return false;
}
}
});
}
}
Here alogin is the name of the form and url: "<?php echo base_url();?>index.php/admin/adminLogin/" is the function path in controller page.
This is the code in Controller page
function adminLogin(){
$this->adminmodel->admin_login();
}
This is the code in Model page
function admin_login(){
$adminname=$this->input->post('txtuname');
$adminpass=$this->input->post('txtupass');
$adminp_decr=md5($adminpass);
$this->db->where('varuname',$adminname);
$this->db->where('varpassword',$adminp_decr);
$query = $this->db->get('tbladmin');
$row=$query->row();
if($row==TRUE){
$adminname=$row->varuname;
$id=$row->intaid;
$userdata = array(
'ausername=' =>$adminname,
'aid' => $id,
'logged_in' => TRUE
);
$this->session->set_userdata($userdata);
echo 1;
}
else
{
echo "Invalid user name or password";
}
}
But when i click on the Login buttton nothing will happen(the click_next() is called and given admin,admin as username ,password).What is the reason?This is working in our server But not working in client’s server?
Since you’re posting to the controller method, I would recommend grabbing the POST variables in that method and passing them via parameters to the model function. According to MVC, the controller should be working with POST variables and not the model.
Try this:
It’s a minor change, but the code adheres more to MVC principles. Plus, I suspect that your POST variables might not be making it past the call to the model’s admin_login() method.