0

未定義のインデックス: C:\wamp\www\gcm_server_php\check_user.phpの phone_no 11行目で
このエラーが発生しますが、PHP コードはブラウザーで正常に動作し、応答コード 200 を取得します

Android コード

 package com.pushnotification;

 import org.apache.http.HttpResponse;
 import org.apache.http.util.EntityUtils;
 import org.json.JSONObject;

 import android.app.Activity;
 import android.os.Bundle;
 import android.util.Log;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.Button;
 import android.widget.Toast;

 public class JsonArray extends Activity {

Button btnAsonArray;
JSONObject listOfNumbers = null;

String listNumber;
String browserString = "?phone_no=";
String url = CommonUtilities.LOCAL_CHECK_USER_URL;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.josn_array);

    btnAsonArray = (Button) findViewById(R.id.josnArray);
    btnAsonArray.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            readNumberAndNAme();

            // Log.e("", "In Onclick Methos :- " + jsonObject);
        }
    });
}

private void readNumberAndNAme() {
    try {
        Log.e("", "in Read Numbers And Name Method :- ");

        listNumber = "9465383066";
        HttpResponse re = HTTPPoster
                .doPost(url, browserString + listNumber);
        String temp = EntityUtils.toString(re.getEntity());

        Log.e("", "=======Task Comleted sucessfully ========" + temp);
        int j = 0;
        while (j != 5) {
            Toast.makeText(this, "Length of Result :- " + temp.length(),
                    Toast.LENGTH_LONG).show();
            j++;
        }

        if (temp.compareTo("SUCCESS") == 0) {

            Log.e("", "Sending complete!");

        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

}

アンドロイドの別のクラス

 package com.pushnotification;

 import java.io.IOException;

 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.message.BasicHeader;
 import org.apache.http.protocol.HTTP;

 import android.util.Log;

 public class HTTPPoster {

public static HttpResponse doPost(String url, String c)
        throws ClientProtocolException, IOException {

    Log.e("", "URL from Http Poster Class :- " + url
            + "Data to send server :- " + c);

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost request = new HttpPost(url);

    request.setHeader("Content-type", "application/json");

    HttpEntity entity;
    StringEntity s = new StringEntity(c.toString());

    s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
            "application/json"));
    entity = s;
    request.setEntity(entity);

    HttpResponse response;
    response = httpclient.execute(request);

    Log.e("", "================Method Executed sucessfully================"
            + response);
    return response;
}

 }

PHPコード

 $phone_no = $_REQUEST["phone_no"];


include_once 'GCM.php';
include_once 'db_functions.php';
$gcm = new GCM();
$db = new db_functions();
$result = $db->isPhoneExisted($phone_no);
if($result>0)
{

    $message = array("product" => "abc");


    echo "true";
}
else 
{

    $message = array("product" => "abc");


    echo "false";
 }


?>
4

2 に答える 2

0

変数$phone_noが設定または定義されていないため、このエラーが表示されます

使用する

$phone_no = $_REQUEST["phone_no"];

if(isset($phone_no)){
include_once 'GCM.php';
include_once 'db_functions.php';
$gcm = new GCM();
$db = new db_functions();
$result = $db->isPhoneExisted($phone_no);
if($result>0)
{

    $message = array("product" => "abc");


    echo "true";
}
else 
{

    $message = array("product" => "abc");


    echo "false";
 }
}else{
echo "phone no. is empty";
}

?>
于 2013-08-27T07:37:15.477 に答える
0

$phone_no変数 を設定する必要があります

if(isset($_REQUEST["phone_no"]))  { 
     $phone_no = $_REQUEST["phone_no"];
    }
于 2013-08-27T07:37:18.787 に答える