我的一类应用程序中有以下代码可以正常工作。以下代码片段从远程服务器接收字符串“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);
}
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());
}
而当我尝试在 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());
}
在Android端接收行数或行或列中的数据有不同的方法吗?