I am new to PHP and this is the first try to code. I have a login Form with Email and password,when the user submits the form ,there should be a connection to a MS SQL Server and then Check to see if the values are valid. check1 is being displayed but everything after is not. Is this the correct way to connect to MS sql server?Most articles on the internet are using MYSQL so i can't find much info on SQL Server.
PHP code is present on the same page as the html. I am desperate to know why the code isn't working,Thanks for the help. Here is what i have tried so Far:
HTML code:
<form class="form-horizontal" method="post" action="Login.php">
<input type="email" id="inputEmail" class="form-control" name="username" placeholder="Email address" required >
<input type="password" id="inputPassword" class="form-control" name="password" placeholder="Password" required >
<button class="btn btn-lg btn-primary btn-block" type="submit" name='Submit' value='Submit'>Login</button>
</form>
PHP Code:
if (isset($_POST['Submit']))
{
Login();
}
function Login()
{
$username = trim($_POST['username']);
$password = trim($_POST['password']);
$serverName = "TAREX-09\MSSQLSERVER"; //name of server(locally)
$connectionOptions = array("Database" => "Insurance");
echo 'check1';
//Connect using Windows Authentication.
$conn = sqlsrv_connect($serverName, $connectionOptions);
echo 'check2';
if (!$conn)
{
echo 'failed';
//die(FormatErrors(sqlsrv_errors()));
}
$tsql = "SELECT EmailAddress,Password
FROM Customer_Detail
WHERE EmailAddress=$username AND Password=$password ";
$getlogin = sqlsrv_query($conn, $tsql);
if ($getlogin === false)
{
echo 'Login Failed';
} else
{
echo 'Login Success';
}