Android アプリケーションから mysql データベースにデータを送信しようとしていますが、データは文字列形式 (ユーザーが完了したクイズの結果) であり、何が問題なのかわかりません。
HTTP Post の Android コードは次のとおりです。
// http post
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://ast.ncl-coll.ac.uk/~cmaughan/firesafety/app_results.php");
try {
//Link to quiz string results
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("StaffID","StaffID"));
nameValuePairs.add(new BasicNameValuePair("Forename","Forename"));
nameValuePairs.add(new BasicNameValuePair("Surname", "Surname"));
nameValuePairs.add(new BasicNameValuePair("Score", "Score"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
} catch (Exception e) {
Log.e("log_tag", "Error in http connection " + e.toString());
Toast.makeText(getApplicationContext(),
ここに私のphpがあります:
<?php
include('./inc/connection.inc.php');
connect();
//retrieve the data
$StaffID = $_POST['StaffID'];
$Forename = $_POST['Forename'];
$Surname = $_POST['Surname'];
$Score = $_POST['Score'];
//Insert into the database
$sql = "INSERT INTO tblQuiz (staffid, forename, surname, score) VALUES ('$StaffID', '$Forename', '$Surname', '$Score')";
$result = mysql_query($sql) or die("Could not run query");
// Close connection to the database
mysql_close();
// Echo success
echo "Upload Successful";
?>
HTTP Post メソッドを使用して文字列を送信しようとしているため、配列が間違っていると思います。
注: *クイズの結果は DDMS の mysqllite データベースに送られます。これらの結果を php/mysql データベースにアップロードしたいだけです。*