EDIT. If I echo $row_count, it comes back as 1, so it works up to that point. But still I get the invalid login details statement back.
I set up a login page that leads to the admin area of my site for the client to log in and add text/images etc.
The login page has worked from day one whilst testing on apache/xaamp, but the site when live today, and for some reason now it is impossible to log in. I am using PDO's to connect on the other pages, but this page was written before I moved to PDO, would this make a difference?
The outcome I get is Invalid login details. There are no errors. And I have doubled checked all db host details and made sure I am using a valid username and password!
Any help would be much appreciated. Thanks.
$db=new mysqli ("hostname.db.1and1.com", "myusername", "mypasswd", "dbname");
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
$username=mysqli_real_escape_string($db, $_POST['username']);
$password=mysqli_real_escape_string($db, $_POST['password']);
if ($result = $mysqli->query("SELECT firstname from admin
where username='$username' and password='$password'")) {
$row_count = $result->num_rows;
}
$accepted = false ;
if ($row_count ==1) {
$accepted=setcookie("cookie", "value", time()+18000);
}
if ($accepted==1) {
header ("location:admin_home.php");
} else {
echo "<p class=\"center\">Invalid Login details,
please <a href=\"login.php\">Try again</a></p>";
}