java - Error while receiving data from sql server -
i have following code in 1 class of app works fine. following code snippet recieves string "okay" remote server.
try { list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(2); namevaluepairs.add(new basicnamevaluepair("userid", et1.gettext().tostring())); namevaluepairs.add(new basicnamevaluepair("pass", et2.gettext().tostring())); httppost.setentity(new urlencodedformentity(namevaluepairs)); client.execute(httppost); httpresponse response = client.execute(httppost); httpentity respentity = response.getentity(); if (respentity != null) { // entityutils response content content = entityutils.tostring(respentity); log.d("valueeeeeeeeeeee", content); }
the code php in following:
<?php $host = "localhost"; $user = "admin"; $pass = "123"; $connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<br>"); $userid = mysql_real_escape_string($_post['userid']); $pass = mysql_real_escape_string($_post['pass']); $db_select=mysql_select_db("mydb"); if(!$db_select){ die(mysql_error()); echo "error"; } $query = "select count(1) count_users wp_users user_login = '".$userid."' , user_pass='".$pass."'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); if($row['count_users']>0) { echo "okay"; } else { echo "not found"; } if($medo=mysql_query($query)){ header("localhost/filename"); exit; }else{ echo"<p> error</p>"; die(mysql_error()); }
whereas when try run following code in php gives me error same android code.
<?php $host = "localhost"; $user = "admin"; $pass = "123"; $connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<br>"); $userid = mysql_real_escape_string($_post['userid']); $pass = mysql_real_escape_string($_post['pass']); $db_select=mysql_select_db("mydb"); if(!$db_select){ die(mysql_error()); echo "error"; } $query= "select * wp_users"; $result = mysql_query($query); $num_rows = mysql_num_rows($result); if("$num_rows" > 0) { echo "$num_rows"; } else { echo "not found"; } if($medo=mysql_query($query)){ header("localhost/filename"); exit; }else{ echo"<p> error</p>"; die(mysql_error()); }
is there different way receive number of rows or data in rows or columns @ android end?
first of change
if("$num_rows" > 0) { echo "$num_rows"; }
to
if ($num_rows > 0) { echo $num_rows; }
secondly if want number of rows use query
$query= "select count(*) wp_users";
Comments
Post a Comment