jquery - Checking Login with Ajax + PHP -
i created simple login 2 inputs username , password. im using ajax pass data being used in mobile app. reason, having issue verifying credentials against whats stored in db. using standard pdo , simple ajax formdata call.
my form:
<form method="post" id="userloginform" enctype="multipart/form-data"> <label for="uname">username</label> <input type="text" name="uname" id="uname" data-theme="a" data-mini="true" data-corners="true" /> <label for="upass">password</label> <input type="password" name="upass" id="upass" data-theme="a" data-mini="true" data-corners="true" /> <p></p> <center> <button type="submit" data-theme="a" data-mini="true"> <small>login</small> </button> </center> </form>
my ajax post method in head of doc (in same document form):
var fd = new formdata( $(this)[0] ); var username = $("#uname").val(); var password = $("#upass").val(); $.ajax({ type: 'post', processdata: false, contenttype: false, async: false, //data: { user: username, pass: password },// data: fd, url: 'urltomylogincheck/loginchk.php', success: function(html){ if(html==1) { //$("#add_err").html("right username or password"); sessionstorage.setitem("user",username); alert('wait while log in'); window.location.href = 'user.html'; } else { $("#add_err").css('display', 'inline', 'important'); $("#add_err").html("<div style='background: red; padding: 2px 5px 5px 5px;color:white;'> <small>wrong username or password</small></div><br/>"); } }, beforesend:function() { $("#add_err").css('display', 'inline', 'important'); $("#add_err").html("<img src='img src='assets/img/ajax-loader.gif' /> loading...<br/>") } }); return false; }); });
an simple php check service:
session_start(); $user = $_post['uname']; $pass = md5($_post['upass']); if(isset($user)) { $check = $conn->prepare("select * profiletbl user = :username , pass = :password"); $check->bindparam(':username', $user); $check->bindparam(':password', $pass); $check->execute(); $count = $check->rowcount(); $row = $check-> fetch(); if($count==1) { $_session['uname'] = $row['user']; ///header("location: home.html"); } else { $errmsg_arr[] = 'username , password not found'; $errflag = true; session_write_close(); ///header("location: about.html"); exit(); } $check = null;
when test login, response logincheck.php says:
i've created login before no problem using mysqli reason, im starting believe in ajax causing stink. great.
Comments
Post a Comment