I am making a user authentication page using CodeIgniter

The problem is that the query is not retrieving the correct value from the database rather it is not retrieving any value. Whenever I try to print the variable which holds the result, it is blank.
I am attaching a part of the code



This is the code in model



$db = new PDO('mysql:host=localhost;dbname=login;charset=utf8', 'root', 'learningit');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $db->prepare("SELECT id FROM members WHERE userid='$username' AND password='$password'");
$stmt->execute();
$var=$stmt->fetch(PDO::FETCH_ASSOC);

foreach ((array)$var as $row) {
print_r($row);
return $row;


& this is the controller part



public function check()
{

$this->load->model('test_model');

$result=$this->test_model->data_check();

if($result[0]==1)
{
$this->call();
}
else if($result[0]==2)
{
$this->call1();
}
else if($result[0]==3)
{
$this->call2();
}
else
{
echo "Invalid id/password";
}
}


Answers

You might be missing $username and $password declaration in your model



$username = $this->input->post('username'); // change this depends in your input 
$password = $this->input->post('password'); // change this depends in your input