私は、開始アクティビティとして、PHPを使用してMySQLリモートDBにログインさせる必要のあるアプリケーションを持っています(ユーザーは管理者)。 ユーザが正しくログインしている場合、別のアクティビティが実行され、いくつかの設定を変更した後、サービスを開始し、PHPを介してこのMySQL DBにデータを継続的に送信する必要があります。Android:MySQLサーバーに外部キーを持つユーザーにデータを送信する
このデータは外部キーとしてuser_idにリンクする必要があるため、このデータが正しいuser_idに送信されるようにするにはどうすればよいですか? テーブルcalls_dataに特定のデータを挿入したいのですが、そのためにuser_idフィールドが必要です。
たときにユーザーがログインする、これは私が何をすべきかですので、私はわからない:
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("username", un.getText().toString()));
postParameters.add(new BasicNameValuePair("password", pw.getText().toString()));
String response = null;
try {
response = CustomHttpClient.executeHttpPost("http://10.0.2.2/science/login.php", postParameters);
String res = response.toString();
res = res.replaceAll("\\s+", "");
if (res.equals("1")) {
// We launch main activity to get the app running after successful login
Intent i = new Intent(getApplicationContext(), MtprojectActivity.class);
/* Set the request code to any code you like, you can
* identify the callback via this code
*/
startActivityForResult(i, REQUEST_CODE);
} else {
error.setText(res.toString());
}
} catch (Exception e) {
un.setText(e.toString());
}
しかし、私は、私は他にそれを渡すことができますので、私はDBからのuser_idをつかむ必要があるかどうかわからないですデータを送信するときのアクティビティ。
これが私のDB内のテーブルの構造を次のとおりです。
CREATE TABLE IF NOT EXISTS `calls_data` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`date` varchar(100) DEFAULT NULL,
`duration` varchar(100) DEFAULT NULL,
`type` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(100) DEFAULT NULL,
`password` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
事前のおかげであなたの助けのためにたくさん!