Hi,
Thanks. Yeah I didnt include the database connection and then when I did I put them in the incorrect order. So that is fixed now.
Still getting the Catchable fatal error: Object of class mysqli could not be converted to string error message though.
Must be somewhere in the following. Any ideas as I'm a bit lost?
function processLoginForm ($cn, $formData) {
foreach ($formData as $key => $value) {
switch ($key) {
case 'pword' :
$local[$key] = mysqli_real_escape_string ($cn, sha1(trim(($value))));
break;
case 'uname' :
$local[$key] = mysqli_real_escape_string($cn, (trim($value)));
break;
default :
$local[$key] = mysqli_real_escape_string($cn, sanitiseInput($value));
}
}
return $local;
}
Error in line 18 showin in comments below
function db_authUser($connection, $username = "", $password = "") {
$sql = "SELECT id FROM users WHERE username = $'$username' AND password = '$password'"; // line 18
$result = mysqli_query($connection, $sql);
$numRows = mysqli_num_rows($result);
if ($numRows == 1) {
$row = mysqli_fetch_assoc($result);
return $row['id'];
} else {
return false;
}
}
$login = processLoginForm($cn, $_POST);
if ($uid == db_authUser($login['uname'], $login['pword'], $cn)) {
$user = db_getRowById($uid, "users", $cn);
$_SESSION['uid'] = $user['id'];
$_SESSION['username'] = $user['username'];
$_SESSION['level'] = $user['level'];
$_SESSION['loggedin'] = true;
redirect("admin.php");
} else {
setMessage("Username or password incorrect");
redirect("login.php");
}