I have created API for Login using POST method but it give me error GET method is work.
code of student_login method of contrller Api
class Api extends CI_Controller{
public function student_login() {
$username=$this->input->post['vUserName'];
$password=$this->input->post['vPassword'];
$this->load->model('Api_model');
$result=$this->Api_model->get_login($username,$password);
if(!empty($result))
{
$response["error"]="true";
$response["message"]="You have been successfully login";
echo json_encode(array('result'=>$result));
die( json_encode($response));
}
else
{
$response["error"]="false";
$response["message"]="Invalid Username and Password";
die(json_encode($response));
}
}
}
Model :To load the data of table tbl_students
class Api_model extends CI_Model { public function get_login($name,$pass) { //echo $name,$pass; $this->db->select('iStudentID,class,section,vDivision,vGrno'); $this->db->from('tbl_students');
$this->db->where('vUserName',$name);
$this->db->where('vPassword',$pass);
//$this->db->from('tbl_students');
return $this->db->get()->result_array();
}
}