I want to pass username and password to a php script and check in the database. On the client side I use the following script to make a json object and post it to the php file.
var myobj = {};
myobj["usrname"]= $( "#customer option:selected" ).text();
myobj["usrpass"]= $("#psw").val();
var myjson = JSON.stringify(myobj);
$.ajax({
method: "POST",
url: "checkpass.php",
data: myjson
})
.done(function( msg ) {
alert( msg );
});
On the server side, when I see in firebug, the post is passed as
Parametersapplication/x-www-form-urlencodedDo not sort {"usrname":"XXXXXXX...
JSONusrname "XX"
usrpass "justdoit" Source {"usrname":"XXX","usrpass":"justdoit"}
however when i run the php script to check the query the it returns an error
$usrname = $_POST['usrname'];
$usrpass = $_POST['usrpass'];
$sql = "select count(*) from glusers where EmpName='$usrname' and EmpPass='$usrpass'";
$result = $conn->query($sql);
if($result >0){
$output = 'Success';
} else
{
$output = 'fail';
}
I have tried through all the posts but cannot get this to work.
Thanks in advance.
Regards,
console.log(myjson);