私はアンドロイドに新しく、簡単な登録フォームの開発を習得しようとしています。私はyoutubeチュートリアルに続き、同じコードはgithubで入手できます。
私は自分のマシンにローカルにインストールされたphp-mysqlを使用しています。したがって、URLへのパスのために - 両方の要求だけでなく、ログイン要求を登録し、私は次のURLを使用しています:Androidへの登録フォームがMySQLに公開されていません - localhost
http://192.168.0.101/register.php
http://192.168.0.101/login.php
私が使用してローカルに私のブラウザでこれらのファイルを実行すると:
http://127.0.0.1/register.php
http://127.0.0.1/login.php
をそれはdoesnのエラーを返しません。次のように
レジスタとログインPHPファイル内の接続が行われます。
$con = mysqli_connect("localhost", "root", "ABCABC", "agnya");
ユーザー名とパスワードを提供する時にアプリは3ページ目を開く必要がありますか、私は登録ページを使用して登録する場合、DBを更新する必要がありますログインページを返します。
問題がある:
アプリがエラーなしでローカルVM上で動作する、しかし、詳細を入力し、ログインをクリックするか、ボタンを登録すると、私は何のアクションまたはエラーメッセージを見ることはありません。私は次のように様々な組み合わせでURLを変更しようとしている:
127.0.0.1, 127.0.0.1:3306, 192.168.0.101,192.168.0.101:3306, localhost, 10.0.2.2, 10.0.2.3
、代わりにローカルホストのPHPファイルでは、私はこれらすべてを使用し、これらの様々な組み合わせできました。
私はこの3日間の解決策に苦労していますが、役に立たないものです。私はjsonparser
を使用しなければならない - 私はどこかのようなオプションを見た。
クラウドでホストされているMysqlでテーブルを設定し、クラウドクレデンシャルを使用してもまだ動作しません。何かご意見は?
アプリケーションマニフェスト
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".registerActivity" />
<activity android:name=".userDetailsActivity"></activity>
</application>
RegisterActivity.java
package inagnya.axiomanalytics.www.agnya;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.content.Intent;
import com.android.volley.Response;
import com.android.volley.toolbox.Volley;
import com.android.volley.RequestQueue;
import org.json.JSONException;
import org.json.JSONObject;
public class registerActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
final EditText etNameReg = (EditText) findViewById(R.id.etNameReg);
final EditText etUsernameReg = (EditText) findViewById(R.id.etUsernameLog);
final EditText etPasswordReg = (EditText) findViewById(R.id.etPasswordLog);
final EditText etAgeReg = (EditText) findViewById(R.id.etAgeWel);
final Button btnRegister = (Button) findViewById(R.id.btnRegister);
btnRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String name = etNameReg.getText().toString();
final String username = etUsernameReg.getText().toString();
final String password = etPasswordReg.getText().toString();
final int age = Integer.parseInt(etAgeReg.getText().toString());
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
if (success) {
Intent intent = new Intent(registerActivity.this, LoginActivity.class);
registerActivity.this.startActivity(intent);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(registerActivity.this);
builder.setMessage("Registration Failed")
.setNegativeButton("Retry", null)
.create()
.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
RegisterRequest registerRequest = new RegisterRequest(name,username,password,age,responseListener);
RequestQueue queue = Volley.newRequestQueue(registerActivity.this);
queue.add(registerRequest);
}
});
}
}
RegisterRequest.java
package inagnya.axiomanalytics.www.agnya;
import java.util.HashMap;
import java.util.Map;
import com.android.volley.Response;
import com.android.volley.toolbox.StringRequest;
/**
* Created by mageshpoondi on 08/01/17.
*/
public class RegisterRequest extends StringRequest{
private static final String REGISTER_REQUEST_URL = "http://192.168.0.101/register.php";
private Map<String, String> params;
public RegisterRequest(String name, String username, String password, int age, Response.Listener<String> listener) {
super(Method.POST, REGISTER_REQUEST_URL,listener,null);
params = new HashMap<>();
params.put("name", name);
params.put("username", username);
params.put("password", password);
params.put("age", age + "");
}
@Override
public Map<String, String> getParams() {
return params;
}
}
activity_register.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_register"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="inagnya.axiomanalytics.www.agnya.registerActivity">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="11dp"
android:layout_marginStart="11dp"
android:id="@+id/etNameReg"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="Name" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:layout_below="@+id/etNameReg"
android:id="@+id/etUsernameLog"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignLeft="@+id/etNameReg"
android:layout_alignStart="@+id/etNameReg"
android:hint="Username" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/etPasswordLog"
android:layout_below="@+id/etUsernameLog"
android:layout_alignLeft="@+id/etUsernameLog"
android:layout_alignStart="@+id/etUsernameLog"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="Password" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:layout_below="@+id/etPasswordLog"
android:id="@+id/etAgeWel"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignLeft="@+id/etPasswordLog"
android:layout_alignStart="@+id/etPasswordLog"
android:hint="Age" />
<Button
android:text="Register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/etAgeWel"
android:layout_alignLeft="@+id/etAgeWel"
android:layout_alignStart="@+id/etAgeWel"
android:layout_marginTop="21dp"
android:id="@+id/btnRegister"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
ifconfigコマンドの出力
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether a4:5e:60:c1:9d:6b
inet6 fe80::a65e:60ff:fec1:9d6b%en0 prefixlen 64 scopeid 0x4
inet 192.168.0.101 netmask 0xffffff00 broadcast 192.168.0.255
nd6 options=1<PERFORMNUD>
media: autoselect
status: active
あなたの質問はまだありませんか?あなたが何をしたいのか、何が起こっているのか、起こらないはずですか? –
登録しようとすると、MySqlで登録の詳細が更新されません....ログインしようとすると...ログインできませんでしたが、VMがエラーを返さない。 – Apricot
あなたのPCのIPアドレスを知っていますか?あなたが使用しているローカルサーバーはすべてのファイルを正しく入れていますか? – W4R10CK