I have a database from MariaDB and I'm unsure about how to connect it with my php file. Is there some special thing I need to do with MariaDB to get its host value? Also is what I have for my query relating to the table and data from my database correct? My table from my database is called Users and it contains LoginID and password. Right now whenever I click the submit button it just shows my PHP file.
This is my relavent HTML:
<body>
<div class="mainbox">
<h3 align="center">Log In</h3>
<form role="form" class="form-horizontal" method="POST" action="login.php">
<div class="form-group">
<label for="Username">Username:</label>
<input type="text" class="form-control" name="username" size="40" placeholder="Enter Username">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" name="pass" size="40" placeholder="Enter Password">
</div>
<button id="Submit" type="submit" name="submit" class="btn btn-default">Submit</button>
</form>
</div>
</body>
This is my php file login:
DB_Host is what confuses me since it is how I'm supposed to connect to MariaDB.
<?php
define('DB_HOST', 'localhost');
define('UName', 'hudvs');
define('Pass', 'tnUJ6zbpmy')
define('DB_Name', 'db')
$connect = mysqli_connect(DB_HOST, UName, Pass, DB_Name) or die("Failed to connect to MySQL: " . mysqli_error());
function LogIn()
{
session_start();
if(!empty($_POST['username']))
{
$query = mysqli_query("SELECT * FROM Users where LoginID = '$_POST[username]' AND password = '$_POST[pass]'") or die(mysqli_error());
$row = mysqli_fetch_array($query) or die(mysqli_error());
if(!empty($row['LoginID']) AND !empty($row['password']))
{
$_SESSION['LoginID'] = $row['password'];
echo "Successful login to user profile page!";
}
else
{
echo "You've entered a wrong Username or a wrong password. Please retry";
}
}
}
if(isset($_POST['submit']))
{
LogIn();
}
?>