php - Android - Check if SELECT Statement Return Value in MySQL -
i explain want before getting in codes, have android project, connected mysql database, , have password recovery activity in app, in activity user type email in order log in information, when user click send app check if email exists in database or not, if yes send email , if no notify user.
now, in php side every thing works will, wrote query , returns correct values.
public function getuname($uemail) { if ($uemail != null) { $data = array(); $sql = "select uname `user` `email`= '" . $uemail . "'"; $result = $this->db->query($sql); while ($row = $result->fetch_array(mysqli_assoc)) { $data[] = $row; } return $this->_jsonencode( $data ); } }
i know in php if want check if select statement return value or not write like:
if (mysql_num_rows($result) > 0)
but in android side? have function:
private boolean getuserinfo(string uemail) { string getinfo_url = server_url + "getinfo.php?email=" + uemail; new communicatetoserver().execute(getemail_url); return true; }
i want function return true if select statement returned value, , false otherwise.
thank in advance.
new communicatetoserver().execute(getemail_url);
you must implement communicatetoserver in such way, after executing http request, data received server.
you need implement http request in thread, example using asynctask (or using external libs http requests) , use callback triggered when communicatetoserver receive data returned server.
in case, php script returns json data. need parse received json data java object representation.
you can use example gson library json parsing in android
some notes:
- your php code bad. it's insecure - have sql injection vulnerability
- is field "email" unique in db? (it must be) - if yes, use fetch_row() instead fetch_array()
Comments
Post a Comment