I'm not able to connect with database using jquery ajax.
The below is the login1.html page
<form method='POST'>
<div class="username">
<input type="text" id='name' name="name" class="form-control" placeholder="Enter your username">
<i class="glyphicon glyphicon-user"></i>
</div>
<div class="password">
<input type="password" id='password' name='password' class="form-control" placeholder="Enter your password">
<i class="glyphicon glyphicon-lock"></i>
</div>
<div id="error"></div>
<div class="custom-radio-checkbox">
<input tabindex="1" type="checkbox" class="bluecheckradios">
<label>Remember me</label>
</div>
<script>
$(document).ready(function(){
$('.bluecheckradios').iCheck({
checkboxClass: 'icheckbox_flat-blue',
radioClass: 'iradio_flat-blue',
increaseArea: '20%' // optional
});
});
</script>
<input type="submit" class="btn btn-primary style2" name='submit' id="submit" value="Sign In">
</form>
The form value is transferred through jquery ajax
<script>
$(document).ready(function(){
// jQuery methods go here...
$('#submit').click(function(){
var username = $('#name').val();
var pass = $('#password').val();
var datastring = {username:username,pass:pass};
if($.trim(username).length>0 && $.trim(pass).length>0){
$.ajax({
type: "POST",
url : "process/login.php",
data : datastring,
cache: false,
beforeSend : function(){
$("#submit").val('Connectiing...');
},
success:function(data){
if(data){
window.location.href('http://www.google.com');
}
else{
$('#loginone').shake();
$('#submit').val('Login')
$("#error").html("<span style='color:red'>Error:</span>Invalid Username or Password");
}
}
});
}
return false;
});
});
</script>
** This is the data connection page process/login.php**
<?php
include_once('config.php');
if(isset($_POST['submit'])){
$username = $_POST['username'];
$pass = $_POST['pass'];
$sql = "select id from login where login_name = '".$username."' and login_password = '".$pass."' ";
$result = $conn->query($sql);
if($result->num_row > 0){
echo "connected";
}
}//EOF SUBMIT
?>
When ever i pass the correct credentials i get an error for wrong username and password.
submitinput and u are usingif(isset($_POST['submit'])){in php and sending justvar datastring = {username:username,pass:pass};if(isset($_POST['submit'])){asif(count($_POST) > 0)will workdatainsuccess:function(data){