Я пытаюсь реализовать серверную часть для Android. Forthis в андроида я использую этот код:Как получить значения с Android в PHP
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
// Get the deviceID
nameValuePairs.add(new BasicNameValuePair("reg_id", val[1]));
nameValuePairs.add(new BasicNameValuePair("App_Name",val[2]));
nameValuePairs.add(new BasicNameValuePair("App_Version", val[3]));
Теперь на стороне сервера я хочу, чтобы получить доступ к этим значения и сохранить его в базе данных. Мой код PHP:
include('connectdb.php');
$Reg_ID=$_REQUEST['reg_id'];
$App_Name=$_REQUEST['App_Name'];
$App_Version=$_REQUEST['App_Version'];
if($_REQUEST['reg_id']!='NULL' && $_REQUEST['App_Name']!='NULL' && $_REQUEST['App_Version']!='NULL')
{
mysqli_query($con,"INSERT INTO registration (Reg_ID, APP_Name,App_Version)
VALUES ('".$_REQUEST['reg_id']."', '".$_REQUEST['App_Name']."','".$_REQUEST['App_Version']."')");
}
else
{
}
mysqli_close($con);
но в PHP я получаю эти ошибки:
Примечание: Undefined индекс: reg_id в C: \ XAMPP \ HTDOCS \ GCM \ addReg.php на линии 5
Примечание: Undefined индекс: app_name в C: \ XAMPP \ HTDOCS \ GCM \ addReg.php на линии 6
Примечание: Undefined индекс: APP_VERSION в C: \ XAMPP \ HTDOCS \ GCM \ addReg.php на линии 7
Внимание: mysqli_close() ожидает параметр 1, чтобы быть MySQLi, ресурс приведены в C: \ XAMPP \ HTDOCS \ ГКМ \ addReg.php на линии 24
любая помощь
EDIT
public class SendMail extends AsyncTask<String, String, String> {
private String endResult;
HttpResponse response;
@Override
protected String doInBackground(String... val) {
String url=val[0];
//Log.i("Url", url + "");
// Log.d("C2DM", "Sending registration ID to my application server");
HttpPost post = new HttpPost(url);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("reg_id", val[1]));
nameValuePairs.add(new BasicNameValuePair("App_Name",val[2]));
nameValuePairs.add(new BasicNameValuePair("App_Version", val[3]));
HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is established.
int timeoutConnection = 30000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT)
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 30000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
DefaultHttpClient hc = new DefaultHttpClient(httpParameters);
ResponseHandler<String> res = new BasicResponseHandler();
try {
post.addHeader("Content-Type","application/x-www-form-urlencoded");
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
response = hc.execute(post);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
Log.i("endResult", "" + endResult);
super.onPostExecute(result);
publishProgress(endResult);
}
@Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
String result = values[0];
}
}
Я не разработчик Android, но пытаюсь создать массив json, а затем передать его php. IN php декодирует этот массив и использует его – mukund