Failed to query MySQL database

Description

I want to create a simple login page which will redirect me to an html input form. I use MAMP to connect to the MySQL database. These are the settings in MAMP:

  • WEB Server: Apache
  • Apache Port: 8888
  • MySQL Port: 8889

I work with three documents: login.php, style.css and process.php outlined in the Code. I can successfully access the login page where I type in the email and password for the test user created in the database.

Problem

There are some things that I do not understand.

  1. Why is the proper URL: http://localhost:8888/Login/login.php and not http://localhost:8889/Login/login.php? Afterall, in my phpMyAdmin the settings are Server: localhost:8889 and Database: login.
  2. When I type in test user credentials, it produces: Failed to query database. The name of the database is login.

Code

login.php

<!DOCTYPE HTML>
<html>
<head>
    <title>Login Page</title>
    <link rel="stylesheet" type="text/css" target="_blank" rel="nofollow" href="style.css">
</head>
<body>
    <div id="frm">
        <form action="process.php" method="post">
            <p>
                <label>Email</label>
                <input type="text" id="user" name="user"> 
            </p>
            <p>
                <label>Password</label>
                <input type="password" id="password" name="password"> 
            </p>
            <p>
                <input type="submit" id="button" value="Login"> 
            </p>
        </form>
    </div>
</body>
</html>

process.php

<?php
    $Email = $POST["Email"];
    $Password = $POST["Password"];

//To prevent MySQL injection
    $Email = stripcslashes($Email);
    $Password = stripcslashes($Password);
    $Email = mysqli_real_escape_string($Email);
    $Password = mysqli_real_escape_string($Password);

//Connect to server and select database
    mysqli_connect("localhost","root","123456789");
    mysqli_select_db("login");

//Query the database for user
    $result = mysqli_query("SELECT * FROM users WHERE Email = '$Email' and Password = '$Password'")
        or die("Failed to query database " . mysqli_error());
    $row = mysqli_fetch_array($result);

    if($row["Email"] == $Email && $row["Password"] == $Password && ("" !== $username || "" !== $password)) {
        echo "Login successfull! Welcome " .$row["Email"];
    } else {
        echo "Failed to login :/";    
    };

?>

The 8889 port allows you to connect to MySQL. When you access a URL in browser it will try to connect to your apache which is accessible on port 8888. Hence 8888 is correct. Secondly, check this out for mysqli_query, you should pass a proper connection handle. https://www.w3schools.com/php/func_mysqli_query.asp