Returning success on query successfully in PHP to java -
i need check if username present in database.if login. after login,i need response sent php file java class saying success. when access result array in java file using json,it giving null though username present in database.
any help?
i using below php , java code
<?php include("db_config.php"); $myusername = $_get['username']; $mypassword = $_get['password']; $sql="select id tablename username='$myusername' , password='$mypassword'"; echo $sql; $result=mysql_query($sql); $row=mysql_fetch_array($result); $active=$row['active']; $count=mysql_num_rows($result); if($count==1) { $result['login'] == 'success'; } else { $result['login'] == 'failed'; } echo json_encode($result);
this java code
btnlogin.addactionlistener(new actionlistener() { public void actionperformed(actionevent arg0) { username= textfieldusername.gettext().tostring(); password = textfieldpassword.gettext().tostring(); // discount = textfielddiscount.gettext().tostring(); list<namevaluepair> params = new arraylist<namevaluepair>(); params.add(new basicnamevaluepair("username",username)); params.add(new basicnamevaluepair("password",password )); jsonobject json = jparser.makehttprequest(url_all_products, "get", params); try { status = json.getstring(tag_success); system.out.println(" status "+status); if(status.equalsignorecase("success")) { system.out.println("login success"); } } catch (jsonexception e) { e.printstacktrace(); } } });
also,i tried if(response.getstatusline().getstatuscode()==200) returns 200 if ok from server.
[edit: code reformation]
use code java
jsonobject json = (jsonobject)jparser.makehttprequest(url_all_products, "get", params); try { //status = json.getstring(tag_success); string status = (string) json.get("login"); system.out.println(" status "+status); if(status.equalsignorecase("success")) { system.out.println("login success"); } }
Comments
Post a Comment