AndroidアプリケーションからWebサーバーにデータを送信し、mysqlを使用してデータベースに送信しようとしていますが、エラーはないようですが、コードが機能しません
アンドロイド Java コード:
String categorys=category.getText().toString();
String authors = author.getText().toString();
String quess = question.getText().toString();
String anss = answer.getText().toString();
try {
JSONObject json = new JSONObject();
json.put("category",categorys);
json.put("ques",quess);
json.put("ans",anss);
json.put("authors",authors);
postData(json);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
public void postData(JSONObject json) throws JSONException {
HttpClient httpclient = new DefaultHttpClient();
try {
HttpPost httppost = new HttpPost("http://shlomo.webuda.com/androidtomy.php");
List<NameValuePair> nvp = new ArrayList<NameValuePair>(2);
nvp.add(new BasicNameValuePair("json", json.toString()));
//httppost.setHeader("Content-type", "application/json");
httppost.setEntity(new UrlEncodedFormEntity(nvp));
HttpResponse response = httpclient.execute(httppost);
if(response != null) {
InputStream is = response.getEntity().getContent();
//input stream is response that can be shown back on android
}
}
catch (Exception e)
{
e.printStackTrace();
}
}`
phpコード
mysql_connect("something","something","something");
mysql_select_db("something");
$json = $_SERVER['HTTP_JSON'];
echo "JSON: \n";
var_dump($json);
echo "\n\n";
$data = json_decode($json,true);
var_dump($data);
$category=$data['category'];
$author=$data['authors'];
$question=$data['ques'];
$answer=$data['ans'];
$sql = 'INSERT INTO Ques(Ques_Author, Ques_Question,Ques_Answer,Ques_Category,Ques_Approve) values("category","author","question","answer","0")';
mysql_query($sql);
}
?>