[英]Error while receiving data from sql server
I have the following code in one class of my app that works fine. 我的应用程序的一类中有以下代码,可以正常工作。 The following code snippet recieves a string "Okay" from a remote server. 以下代码段从远程服务器接收字符串“ Okay”。
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 to get the response content
content = EntityUtils.toString(respEntity);
Log.d("valueeeeeeeeeeee", content);
}
The code for the php is in the following: php的代码如下:
<?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) as count_users from wp_users where user_login = '".$userid."' and 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 I try to run the following code in php it gives me an error for the same android code. 而当我尝试在php中运行以下代码时,相同的android代码却给我一个错误。
<?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 * FROM 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 a different way to receive the number of rows or the data in rows or columns at the Android end? 有没有其他方法可以在Android端接收行数或行或列中的数据?
First of all change 首先改变
if("$num_rows" > 0)
{
echo "$num_rows";
}
to 至
if ($num_rows > 0)
{
echo $num_rows;
}
Secondly if you just want to get number of rows use query 其次,如果您只想获取行数,请使用查询
$query= "SELECT COUNT(*) FROM wp_users";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.