Getting json response for android from PHP -
i newbie in php, kindly pardon me if looks silly. still learning step step of online forums , stack community.
i have form online code below:
<?php define('dir_application', str_replace('\'', '/', realpath(dirname(__file__))) . '/'); include(dir_application."config.php"); ob_start(); session_start(); $msg = 'none'; $sql = ''; if(isset($_post['email']) && $_post['email'] != '' && isset($_post['password']) && $_post['password'] != ''){ if($_post['usertype'] == 'admin'){ //here admin $sql= mysql_query("select * admin a_email = '".make_safe($_post['email'])."' , password = '".make_safe($_post['password'])."'",$link); } else if($_post['usertype'] == 'teacher'){ //here teacher $sql= mysql_query("select * teacher t_email = '".make_safe($_post['email'])."' , t_password = '".make_safe($_post['password'])."'",$link); } else if($_post['usertype'] == 'student'){ //here student $sql= mysql_query("select * student s_email = '".make_safe($_post['email'])."' , s_password = '".make_safe($_post['password'])."'",$link); } else if($_post['usertype'] == 'parents'){ //here parent $sql= mysql_query("select * parent p_email = '".make_safe($_post['email'])."' , p_password = '".make_safe($_post['password'])."'",$link); } else if($_post['usertype'] == 'librarian'){ //here employee $sql= mysql_query("select * user u_email = '".make_safe($_post['email'])."' , u_password = '".make_safe($_post['password'])."'",$link); } else if($_post['usertype'] == 'accountant'){ //here employee $sql= mysql_query("select * user u_email = '".make_safe($_post['email'])."' , u_password = '".make_safe($_post['password'])."'",$link); } if($row = mysql_fetch_array($sql)){ //here success $_session['objlogin'] = $row; $_session['login_type'] = $_post['usertype']; if($_post['usertype'] == 'admin'){ header("location: dashboard.php"); die(); } else if($_post['usertype'] == 'teacher'){ header("location: t_dashboard.php"); die(); } else if($_post['usertype'] == 'student'){ header("location: s_dashboard.php"); die(); } else if($_post['usertype'] == 'parents'){ header("location: p_dashboard.php"); die(); } else if($_post['usertype'] == 'accountant'){ header("location: a_dashboard.php"); die(); } else if($_post['usertype'] == 'librarian'){ header("location: l_dashboard.php"); die(); } } else{ $msg = 'block'; } } function make_safe($variable) { $variable = strip_tags(mysql_real_escape_string(trim($variable))); return $variable; } ?> <!doctype html> <html> <head> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <title>site title | log in</title> <!-- tell browser responsive screen width --> <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"> <!-- bootstrap 3.3.5 --> <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"> <!-- font awesome --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"> <!-- ionicons --> <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css"> <!-- theme style --> <link rel="stylesheet" href="dist/css/adminlte.min.css"> <!-- icheck --> <link rel="stylesheet" href="plugins/icheck/square/blue.css"> <!-- html5 shim , respond.js ie8 support of html5 elements , media queries --> <!-- warning: respond.js doesn't work if view page via file:// --> <!--[if lt ie 9]> <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script> <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> <![endif]--> </head> <body class="hold-transition login-page"> <div class="login-box"> <div class="login-logo"> <a href="index2.html"><b>site</b> title</a> </div> <!-- /.login-logo --> <div class="login-box-body"> <p class="login-box-msg">sign in start session</p> <form onsubmit="return validationform();" role="form" id="form" method="post"> <div class="form-group has-feedback"> <input type="email" name="email" id="email" class="form-control" placeholder="email"> <span class="glyphicon glyphicon-envelope form-control-feedback"></span> </div> <div class="form-group has-feedback"> <input type="password" name="password" id="password" class="form-control" placeholder="password"> <span class="glyphicon glyphicon-lock form-control-feedback"></span> </div> <div class="form-group has-feedback"> <select class="form-control" name="usertype" id="usertype"> <option value="-1">-- select user type --</option> <option value="admin">admin</option> <option value="teacher">teacher</option> <option value="student">student</option> <option value="parents">parents</option> <option value="accountant">accountant</option> <option value="librarian">librarian</option> </select> </div> <div class="row"> <div class="col-xs-8"> <a href="#">forget password?</a><br> </div> <!-- /.col --> <div class="col-xs-4"> <button type="submit" id="login" class="btn btn-primary btn-block btn-flat">sign in</button> </div> <!-- /.col --> </div> </form> </div> <!-- /.login-box-body --> </div> <!-- /.login-box --> <!-- jquery 2.2.0 --> <script src="plugins/jquery/jquery-2.2.0.min.js"></script> <!-- bootstrap 3.3.5 --> <script src="bootstrap/js/bootstrap.min.js"></script> <!-- icheck --> <script src="plugins/icheck/icheck.min.js"></script> <script> $(function () { $('input').icheck({ checkboxclass: 'icheckbox_square-blue', radioclass: 'iradio_square-blue', increasearea: '20%' // optional }); }); </script> <script type="text/javascript"> function validationform(){ if($("#email").val() == ''){ alert("email required !!!"); $("#email").focus(); return false; } else if($("#password").val() == ''){ alert("password required !!!"); $("#password").focus(); return false; } else if($("#usertype").val() == '-1'){ alert("select user type !!!"); return false; } else{ return true; } } </script> <!-- scripts -at botom reduce load time--> <!-- jquery scripts --> <script src="assets/js/jquery-1.10.2.js"></script> <!-- bootstrap scripts --> <script src="assets/js/bootstrap.min.js"></script> </body> </html>
this form works perfectly.
but issue creating android form online version need json response. tried following in browser:
mydomain.com/index.php?email=user@example.com&password=mypass&usertype=student
this results in same page.
i confused why not entering page. can understand somewhere wrong can't figure out.
kindly please.
as @akhil @vijay , @migueljimenez suggested
i changed $_post
$_request
, worked charm
so, if 1 getting stuck in issue might guys hopefully.
Comments
Post a Comment