I’m making a practice website for signing in, using PHP and MySQL. However, when I click submit, the PHP doesn't execute and get data from my database, but it is opened. I can’t seem to find what's wrong in my coding. I have checked and php is enabled and interpreted.
Here's my HTML file:
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Sign-In</title>
<link href="layout.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="sign-in">
<fieldset style="width:30%"><legend>Sign In Here</legend>
<form method="POST" action="connectivity.php">
Username<br><input type="text" name="username" size="40"><br><br>
Password<br><input type="password" name="password" size="40"><br>
<input id="button" type="submit" name="submit" value="Sign In">
</form>
</fieldset>
</div>
</body>
</html>
Here's my php file:
<?php
define('DB_HOST', 'localhost');
define('DB_NAME', 'databasename');
define('DB_USER', 'root');
define('DB_PASSWORD', 'password');
$con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error());
$db = mysql_select_db(DB_NAME, $con) or die("Failed to connect to MySQL: " . mysql_error());
/*
$ID = $_POST['username'];
$Password = $_POST['password'];
*/
function SignIn()
{
session_start();
if (!empty($_POST['username']))
{
$query = mysql_query("SELECT* FROM Username WHERE username ='$_POST[username]' AND password ='$_POST[password]'", $db) or die(mysql_error());
$row = mysql_fetch_array($query) or die(mysql_error());
if (!empty($row['username']) AND !empty($row['password']))
{
$_SESSION['username'] = $row['password'];
echo "Successfully Signed In.";
}
else
{
echo "Sorry, you entered the wrong username and password. Please Try Again.";
}
}
}
if (isset($_POST['submit']))
{
SignIn();
}
mysql_close($con);
?>
I'm using the tutorial from this website, but have different names. I'm pretty new at this, so when answering please be as specific as possible.