I am trying to perform a php function on click of link
and then get the value from input type text and call perform a select query
so far,
<form name="form" id="form" action="login.php" method="get">
<h1>Login</h1>
<div>
<input name="username" id="username" type="text" class="form-control" placeholder="Username" required="" />
</div>
<div>
<input id="password" type="password" class="form-control" placeholder="Password" required="" />
</div>
<div>
<input id="team" type="text" class="form-control" placeholder="Team" required="" />
</div>
<div>
<a class="btn btn-default submit" type="submit" id="submit" name="submit" onClick='return Logincheck()'>Log in</a>
<br>
<br>
<p class="change_link">Lost your password ??
<!-- <a class="reset_pass" href="?sendcode=true">Lost your password?</a> -->
<a href="#"> Change Password </a>
</p>
</div>
so onclick of submit anchor tag it calls LoginCheck javascript i.e
<script type='text/javascript'>
function Logincheck()
{
var user=document.getElementById("username").value;
var pass=document.getElementById("password").value;
var team=document.getElementById("team").value;
}
it successfully performs this task.
but now i have a php file that contains some database connectivity with function that performs select query
not i want to call that file from above javascript function
the php file is dbConnection.php
<?php
function validateLogin($user,$pass,$team)
{
$serverName = "server";
$connectionOptions = array(
"Database" => "dbName",
"Uid" => "sa",
"PWD" => "123456"
);
//Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions);
$tsql= "SELECT Password,Name,Team FROM Login where Username=?;";
$params = array($user);
$getResults= sqlsrv_query($conn, $tsql,$params);
//echo ("Reading data from table");
if ($getResults == FALSE)
die(FormatErrors(sqlsrv_errors()));
while ($row = sqlsrv_fetch_array($getResults, SQLSRV_FETCH_ASSOC)) {
$password=$row['Password'];
$empName=$row['Name'];
$temaname=$row['Team'];
if($password==$pass && $team==$temaname)
{
echo '<script>
alert("Login Success !!!!")
var newURL = location.href.split("?")[0];
window.history.pushState(null, null, window.location.pathname);
</script>';
}
else
{
echo '<script>
alert("Login Faild !!!!")
var newURL = location.href.split("?")[0];
window.history.pushState(null, null, window.location.pathname);
</script>';
}
}
sqlsrv_free_stmt($getResults);
}
?>
but i dont know how to call the validateLogin(user,pass,team) of above php file from the javascript of my first file
i was trying below code but no luck,
<script type='text/javascript'>
function Logincheck()
{
var user=document.getElementById("username").value;
var pass=document.getElementById("password").value;
var team=document.getElementById("team").value;
alert("hi");
var result=
"<?php
include 'dbConnection.php';
echo validateLogin("2012","hcca123@","BFL");
?>";
alert(result);
}
but i think i am doing something wrong, but not getting the cause. plz help