login und register

Bitte aktiviere JavaScript!
Hallo Zusammen.
Ich bin Neuling in der Welt von Java, und deshalb habe ich veruscht mithilfe von Youtube eine App zu erstellen, mit der man sich Registrieren und Einloggen kann. Jetzt zu meinem Problem. Die App funktioniert soweit, doch wenn ich mit dem Emulator von NOX, auf die Registrier Seite gehe, alles ausfülle und auf den Registrier Button drücke, passiert nichts mehr. Eigentlich sollte man zurück zur Login seite kommen, und die Daten sollten in die Datenbank eingetragen werden, doch das ist auch nicht der Fall. Ich habe mal im Logcat bei Android Studio geschaut, dort waren keine Fehler zu sehen. Hab schon gegoogelt konnte aber nichts finden was mit weiterhilft, könnt ihr mir bitte weiterhelfen.


RegisterRequest Code:
Java:
[SIZE=2]package trucki.spas.de.trucki;


import com.android.volley.Response;
import com.android.volley.toolbox.StringRequest;

import java.util.HashMap;
import java.util.Map;

public class RegisterRequest extends StringRequest {

    private static final String REGISTER_REQUEST_URL ="https://trucki.000webhostapp.com/Register.php.txt";
    private Map<String, String> params;

    public RegisterRequest(String name, String username, int age, String password, 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;
    }
}[/SIZE]

RegisterActivity:
Java:
package trucki.spas.de.trucki;

import android.content.Intent;
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 com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.toolbox.Volley;

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 etAge = (EditText) findViewById(R.id.etAge);
        final EditText etName = (EditText) findViewById(R.id.etName);
        final EditText etUsername = (EditText) findViewById(R.id.etUsername);
        final EditText etPassword = (EditText) findViewById(R.id.etPassword);
        final Button bregister = (Button) findViewById(R.id.bregister);

bregister.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        final String name = etName.getText().toString();
        final String username = etUsername.getText().toString();
        final String passwort = etPassword.getText().toString();
        final int age = Integer.parseInt(etAge.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, MainActivity.class);
                        RegisterActivity.this.startActivity(intent);
                    }else{
                        AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
                        builder.setMessage("Hoppla etwas ist schief geloffen, versuch es nochmal :)")
                                .setNegativeButton("Retry", null)
                                .create()
                                .show();




                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }


            }
        };



        RegisterRequest registerRequest = new RegisterRequest(name, username, age, passwort, responseListener );
        RequestQueue queue = Volley.newRequestQueue(RegisterActivity.this);
        queue.add(registerRequest);


    }

});

    }



}


Login.php
Java:
<?php
    $con = mysqli_connect("trucki.000webhostapp.com", "id2604106_brilz",  "id2604106_trucki");
   
    $username = $_POST["username"];
    $password = $_POST["password"];
   
    $statement = mysqli_prepare($con, "SELECT * FROM user WHERE username = ? AND password = ?");
    mysqli_stmt_bind_param($statement, "ss", $username, $password);
    mysqli_stmt_execute($statement);
   
    mysqli_stmt_store_result($statement);
    mysqli_stmt_bind_result($statement, $userID, $name, $age, $username, $password);
   
    $response = array();
    $response["success"] = false;  
   
    while(mysqli_stmt_fetch($statement)){
        $response["success"] = true;  
        $response["name"] = $name;
        $response["age"] = $age;
        $response["username"] = $username;
        $response["password"] = $password;
    }
   
    echo json_encode($response);
?>

Register.php
Java:
<?php
    $con = mysqli_connect("trucki.000webhostapp.com", "id2604106_brilz",  "id2604106_trucki");
   
    $name = $_POST["name"];
    $age = $_POST["age"];
    $username = $_POST["username"];
    $password = $_POST["password"];
    $statement = mysqli_prepare($con, "INSERT INTO user (name, username, age, password) VALUES (?, ?, ?, ?)");
    mysqli_stmt_bind_param($statement, "siss", $name, $username, $age, $password);
    mysqli_stmt_execute($statement);
   
    $response = array();
    $response["success"] = true;  
   
    echo json_encode($response);
?>
Logcat wenn man auf Registrieren drückt.
Java:
08-27 18:41:35.608 481-502/? D/SettingsProvider: User 0 external modification to /data/data/com.android.providers.settings/databases/settings.db; event=8
08-27 18:41:35.608 481-502/? D/SettingsProvider: User 0 updating our caches for /data/data/com.android.providers.settings/databases/settings.db
08-27 18:41:35.818 1981-2124/? I/qtaguid: Tagging socket 48 with tag 471312e400000000(1192432356) for uid -1 failed errno=-13
08-27 18:41:35.818 1981-2124/? I/NetworkManagementSocketTagger: tagSocketFd(48, 1192432356, -1) failed with errno-13
08-27 18:41:36.328 1981-2124/? I/qtaguid: Tagging socket 52 with tag 471312e400000000(1192432356) for uid -1 failed errno=-13
08-27 18:41:36.328 1981-2124/? I/NetworkManagementSocketTagger: tagSocketFd(52, 1192432356, -1) failed with errno-13
08-27 18:41:36.328 1981-2124/? I/qtaguid: Untagging socket 52 failed errno=-13
08-27 18:41:36.328 1981-2124/? W/NetworkManagementSocketTagger: untagSocket(52) failed with errno -13
08-27 18:41:36.328 1981-2124/? I/qtaguid: Tagging socket 52 with tag 471312e400000000(1192432356) for uid -1 failed errno=-13
08-27 18:41:36.328 1981-2124/? I/NetworkManagementSocketTagger: tagSocketFd(52, 1192432356, -1) failed with errno-13
08-27 18:41:36.328 1981-2124/? I/qtaguid: Untagging socket 52 failed errno=-13
08-27 18:41:36.328 1981-2124/? W/NetworkManagementSocketTagger: untagSocket(52) failed with errno -13
08-27 18:41:36.328 1981-2124/? I/qtaguid: Tagging socket 52 with tag 471312e400000000(1192432356) for uid -1 failed errno=-13
08-27 18:41:36.328 1981-2124/? I/NetworkManagementSocketTagger: tagSocketFd(52, 1192432356, -1) failed with errno-13
08-27 18:41:36.328 1981-2124/? I/qtaguid: Untagging socket 52 failed errno=-13
08-27 18:41:36.328 1981-2124/? W/NetworkManagementSocketTagger: untagSocket(52) failed with errno -13
08-27 18:41:36.328 1981-2124/? I/qtaguid: Tagging socket 52 with tag 471312e400000000(1192432356) for uid -1 failed errno=-13
08-27 18:41:36.328 1981-2124/? I/NetworkManagementSocketTagger: tagSocketFd(52, 1192432356, -1) failed with errno-13
08-27 18:41:36.328 1981-2124/? I/qtaguid: Untagging socket 52 failed errno=-13
08-27 18:41:36.328 1981-2124/? W/NetworkManagementSocketTagger: untagSocket(52) failed with errno -13
08-27 18:41:36.328 1981-2124/? I/qtaguid: Tagging socket 52 with tag 471312e400000000(1192432356) for uid -1 failed errno=-13
08-27 18:41:36.328 1981-2124/? I/NetworkManagementSocketTagger: tagSocketFd(52, 1192432356, -1) failed with errno-13
08-27 18:41:36.328 1981-2124/? I/qtaguid: Untagging socket 52 failed errno=-13
08-27 18:41:36.328 1981-2124/? W/NetworkManagementSocketTagger: untagSocket(52) failed with errno -13
08-27 18:41:36.328 1981-2124/? I/qtaguid: Tagging socket 52 with tag 471312e400000000(1192432356) for uid -1 failed errno=-13
08-27 18:41:36.328 1981-2124/? I/NetworkManagementSocketTagger: tagSocketFd(52, 1192432356, -1) failed with errno-13
08-27 18:41:36.328 1981-2124/? I/qtaguid: Untagging socket 52 failed errno=-13
08-27 18:41:36.328 1981-2124/? W/NetworkManagementSocketTagger: untagSocket(52) failed with errno -13
08-27 18:41:36.468 1981-2124/? I/qtaguid: Tagging socket 52 with tag 471312e400000000(1192432356) for uid -1 failed errno=-13
08-27 18:41:36.468 1981-2124/? I/NetworkManagementSocketTagger: tagSocketFd(52, 1192432356, -1) failed with errno-13
08-27 18:41:36.468 1981-2124/? I/qtaguid: Untagging socket 48 failed errno=-13
08-27 18:41:36.468 1981-2124/? W/NetworkManagementSocketTagger: untagSocket(48) failed with errno -13
08-27 18:41:36.468 1981-1981/? W/System.err: org.json.JSONException: Value <?php of type java.lang.String cannot be converted to JSONObject
08-27 18:41:36.498 1981-1981/? W/System.err:     at org.json.JSON.typeMismatch(JSON.java:111)
08-27 18:41:36.498 1981-1981/? W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:159)
08-27 18:41:36.498 1981-1981/? W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:172)
08-27 18:41:36.498 1981-1981/? W/System.err:     at trucki.spas.de.trucki.RegisterActivity$1$1.onResponse(RegisterActivity.java:45)
08-27 18:41:36.498 1981-1981/? W/System.err:     at trucki.spas.de.trucki.RegisterActivity$1$1.onResponse(RegisterActivity.java:39)
08-27 18:41:36.498 1981-1981/? W/System.err:     at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
08-27 18:41:36.498 1981-1981/? W/System.err:     at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
08-27 18:41:36.498 1981-1981/? W/System.err:     at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
08-27 18:41:36.498 1981-1981/? W/System.err:     at android.os.Handler.handleCallback(Handler.java:733)
08-27 18:41:36.498 1981-1981/? W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
08-27 18:41:36.498 1981-1981/? W/System.err:     at android.os.Looper.loop(Looper.java:136)
08-27 18:41:36.498 1981-1981/? W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5019)
08-27 18:41:36.498 1981-1981/? W/System.err:     at java.lang.reflect.Method.invokeNative(Native Method)
08-27 18:41:36.498 1981-1981/? W/System.err:     at java.lang.reflect.Method.invoke(Method.java:515)
08-27 18:41:36.498 1981-1981/? W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
08-27 18:41:36.498 1981-1981/? W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
08-27 18:41:36.498 1981-1981/? W/System.err:     at dalvik.system.NativeStart.main(Native Method)
 
A

Anzeige




Vielleicht hilft dir unser Java-Tutorial hier weiter —> (hier klicken)
Das hier:
dort waren keine Fehler zu sehen
passt mit dem nicht wirklich zusammen:rolleyes:
08-27 18:41:36.468 1981-1981/? W/System.err: org.json.JSONException: Value <?php of type java.lang.String cannot be converted to JSONObject
08-27 18:41:36.498 1981-1981/? W/System.err: at org.json.JSON.typeMismatch(JSON.java:111)
08-27 18:41:36.498 1981-1981/? W/System.err: at org.json.JSONObject.<init>(JSONObject.java:159)
08-27 18:41:36.498 1981-1981/? W/System.err: at org.json.JSONObject.<init>(JSONObject.java:172)
08-27 18:41:36.498 1981-1981/? W/System.err: at trucki.spas.de.trucki.RegisterActivity$1$1.onResponse(RegisterActivity.java:45)
08-27 18:41:36.498 1981-1981/? W/System.err: at trucki.spas.de.trucki.RegisterActivity$1$1.onResponse(RegisterActivity.java:39)
08-27 18:41:36.498 1981-1981/? W/System.err: at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
08-27 18:41:36.498 1981-1981/? W/System.err: at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
08-27 18:41:36.498 1981-1981/? W/System.err: at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
08-27 18:41:36.498 1981-1981/? W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
08-27 18:41:36.498 1981-1981/? W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
08-27 18:41:36.498 1981-1981/? W/System.err: at android.os.Looper.loop(Looper.java:136)
08-27 18:41:36.498 1981-1981/? W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5019)
08-27 18:41:36.498 1981-1981/? W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
08-27 18:41:36.498 1981-1981/? W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
08-27 18:41:36.498 1981-1981/? W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
08-27 18:41:36.498 1981-1981/? W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
08-27 18:41:36.498 1981-1981/? W/System.err: at dalvik.system.NativeStart.main(Native Method)
 
Ja sonst greifst du natürlich auf ein txt File zu. Das wird einfach nur gelesen. Natürlich muss die Datei am Server auch wirklich eine PHP Datei sein und kein ".php.txt"
 
A

Anzeige




Hier lernst du alle wichtigen Java-Grundlagen.
Passende Stellenanzeigen aus deiner Region:

Neue Themen

Oben