I want my code to check if the username and password exist in my database. It does work hardcoded, but I want to do it with a database.Right now this is what I have:
Try this: (i have used mysql object oriented,if you want you can use other version)
if(isset($_POST["name"], $_POST["password"])) {
$name = $_POST["name"];
$password = $_POST["password"];
$select1 = "SELECT password FROM USERS WHERE username = '".$name."'";
$result1=$conn->query($select1);
$row1=$result1->fetch_assoc();
$select2 = "SELECT username FROM USERS WHERE password = '".$password."'";
$result2=$conn->query($select2);
$row2=$result2->fetch_assoc();
if($name == $row2["username"] && $password == $row1["password"])
{
$_SESSION["logged_in"] = true;
$_SESSION["naam"] = $name;
}
else
{
echo'The username or password are incorrect!';
}