php - Check mysql data with android -


i got strange (at least me) problem. want check if email address, that's on android device in database. got code on server side:

<?php include('db_connect.php'); $db = new _db_connect(); $db->connect();      if(isset($_post['email'])){          $accountmail = $_post['email'];         $result = mysql_query("select email gcm_users;");         $count = mysql_num_rows($result);         while($row = mysql_fetch_array($result)){             if($row['email'] == $accountmail){                 echo "e-mail found";             }else{                 echo "not found";             }         }     }     ?> 

i post account email android file. mail in database echo "e-mail found" , see on android. if e-mail not in database, see nothing. heres function use on android far:

protected void doinbackground(string... params) {     try{         string accountmail;         inputstream inputstream;         string status;         //get account e-mail         accountmail = registerdeviceonraspberrypiserver.getaccount(context);          //testoutput         system.out.println("found mail is: -> " + accountmail);          httpclient httpclient = new defaulthttpclient();         httppost httppost = new httppost("http://checkregistration.php");         httppost.setheader("content-type", "application/x-www-form-urlencoded;charset=utf-8");         list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>();         namevaluepairs.add(new basicnamevaluepair("email", accountmail));         httppost.setentity(new urlencodedformentity(namevaluepairs));         httpresponse httpresponse = httpclient.execute(httppost);         inputstream = httpresponse.getentity().getcontent();         status = registerdeviceonraspberrypiserver.convertinputstreamtostring(inputstream);         system.out.println("status: " + status);      }catch (exception e){         e.printstacktrace();     }      return null; } 

so said, status: + status print gives me response, when mail inserted, none when theres nothing in db.

the second question is, there maybe better way check, whether account e-mail in database or not?

1) problem while loop condition.

while($row = mysql_fetch_array($result)){ 

the code inside loop run if there @ least 1 result (this because mysql_fetch_array returns false empty result sets).

in event there no emails, condition false , code inside loop skipped. why seeing nothing when email doesn't exist

2) don't think have worry best possible solution problem. close. simplest solution can think of doesn't need while loop. can use count variable declared above while loop. if number of rows returned query (count) = 0, email doesnt exist, else exists.

optional extra: if wanted check duplicate email entries in db check if count > 1

tangent: ran similar problems when using sqlite db local storage. basically, when query sqlite database, result cursor object contains rows , data. cursor has method 1 used in while loop. easy forget it's weird behavior in event cursor object empty

hope helps


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -