0

アプリの 1 つのクラスに、正常に動作する次のコードがあります。次のコード スニペットは、リモート サーバーから文字列 "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側で行数または行または列のデータを受け取る別の方法はありますか?

4

1 に答える 1