0
私は、ユーザが自分の名前、ユーザ名、およびパスワードを入力するアクティビティを持っています。この情報をMySQLデータベースのエントリとして送信したいと思います。ここに私のコードです:Android - MySQLデータベースにログイン情報を送信
protected String doInBackground(String... params) {
String reg_url = "http://MyIPAddress:ServerPort#/Register.php";
String name = params[1];
String user_name = params[2];
String user_pass = params[3];
try {
URL url = new URL(reg_url);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
OutputStream OS = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(OS, "UTF-8"));
String data = URLEncoder.encode("user", "UTF-8") + "=" + URLEncoder.encode(name, "UTF-8") + "&" +
URLEncoder.encode("user_name", "UTF-8") + "=" + URLEncoder.encode(user_name, "UTF-8") + "&" +
URLEncoder.encode("user_pass", "UTF-8") + "=" + URLEncoder.encode(user_pass, "UTF-8");
bufferedWriter.write(data);
bufferedWriter.flush();
bufferedWriter.close();
OS.close();
return "Registration Success!";
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
コードは実行されますが、プログラムは実行された後もデータベースは空のままです。ここに私のPHPファイル(Register.php)は次のとおりです。
<?php
require "Connection.php"; //Establishes connection to database
$name = $_POST["user"];
$user_name = $_POST["user_name"];
$user_pass = $_POST["user_pass"];
$sql_query = "insert into user_info values('$name','$user_name','$user_pass');";
if (mysqli_real_query($link, $sql_query)) {
echo "<h1> Data Insertion Success! </h1>";
}
else {
echo "Data Insertion Error...";
}
?>
とデータベース(Connection.php)に接続するためのコード:
<?php
$link = mysqli_init();
$success = mysqli_real_connect($link,$host,$user,$password,$db,$port);
if($success) {
echo "<h1> Success! </h1>";
}
else {
echo "Error...".mysqli_connect_error();
}
?>
私はここで何かが足りないのですか?私は喜んであなたの助けに感謝します。ありがとう!ここで
このデータを投稿するときに実行されるサーバー側のコードはどこですか? – RiggsFolly
あなたが間違っていることに追いつくためにyoutubeチュートリアルでPLOWしません。あなたは[最小限の、完全で検証可能な例](http://stackoverflow.com/help/mcve)を作成する方法をお読みください – RiggsFolly
sererがリクエストを受け取ったことを確認しましたか?もしそうなら、その面でデバッグしてどこが失敗しているのか確認してください。 –