[eluser]SparkyCola[/eluser]
Hi,
I'm a bit stuck. In PHP, this is what I want to do, just as a rough idea:
Code:
$query = "SELECT * FROM users WHERE username='$user_name' AND password='$password'";
$result = mysql_query($query, $connection) or die ('error making query');
$affected_rows = mysql_num_rows($result);
if($affected_rows == 1) {
// Validated so continue...
} else {
// Not validated so error
}
In CI this is what I have:
Code:
function _validation($user_name, $password) {
$rules['username'] = "required|callback_username_check";
$rules['password'] = "required|";
$this->validation->set_rules($rules);
}
function username_check($user_name) {
$query = $this->db->query("SELECT * FROM users WHERE username = '$user_name' LIMIT 1");
$row = $query->row_array();
if ($query->num_rows() == 0) {
$this->validation->set_message('username_check', 'Not found in the user database');
return FALSE;
} else {
$db_username = $row['username'];
if ($user_name == $db_username) {
return TRUE;
} else {
$this->validation->set_message('username_check', 'Not found in the user database');
return FALSE;
}
}
}
I'd appreciate any help, just not sure how to achieve the same result - i.e. checking the username AND password together. I could do a callback thing with password as well, but I don't want to do that in case the username is in the database, and the password is in the DB too, but not together on the same row. Thanks,
Sparky