Hey Jungs Ich versuche, Registrierungsseite mit mysqli und PHP für Backend und Java für Front-End zu machen. Meine PHP Connection Datei funktioniert Datei, auch wenn ich Daten eingefügt habe, als ich versuchte, Daten mit Android-Anwendung einzufügen, die es nicht einfügt, und sogar es zeigt keinen Fehler im Protokoll.Android Mysql Connection Error
Ich bin Begginer in Android. Bitte verzeihen Sie, wenn Sie einen Fehler gefunden haben.
Hier ist meine Datei einfügen
require_once('dbConnect.php');
$email = $_POST['email'];
$password = $_POST['password'];
$full_name = $_POST['full_name'];
$registration_num = $_POST['registration_num'];
$contact_num = $_POST['contact_num'];
$sql = "INSERT INTO tblregistration (Email, Password,Full_name,Registration_number,Contact_number) VALUES ($email,$password,$full_name,$registration_num,$contact_num)";
if(mysqli_query($con,$sql)) {
echo "Successful";
}
mysqli_close($con);
Hier ist meine Registrierung Seite ist
b1 = (Button)findViewById(R.id.button);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
str_email = "a";
str_password = "a";
str_full_name = "a";
str_registration_num = "a";
str_contact_number = "a";
new InsertData().execute();
}
});
private class InsertData extends AsyncTask<String, Void, String> {
String JSON_STRING;
JSONObject jsonObject = null;
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show();
}
@Override
protected String doInBackground(String... params) {
JSONParser rh = new JSONParser();
HashMap<String, String> data = new HashMap<>();
data.put("email", str_email);
data.put("password", str_password);
data.put("full_name", str_full_name);
data.put("registration_num", str_registration_num);
data.put("contact_num", str_contact_number);
JSON_STRING = rh.sendPostRequest(AppConfig.URL_REGISTER, data);
return JSON_STRING;
}
}
Hier ist meine HttpURLConnection Datei
public String sendPostRequest(String requestURL,
HashMap<String, String> postDataParams) {
//Creating a URL
URL url;
//StringBuilder object to store the message retrieved from the server
StringBuilder sb = new StringBuilder();
try {
//Initializing Url
url = new URL(requestURL);
//Creating an httmlurl connection
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//Configuring connection properties
conn.setReadTimeout(15000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
//Creating an output stream
OutputStream os = conn.getOutputStream();
//Writing parameters to the request
//We are using a method getPostDataString which is defined below
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
writer.write(getPostDataString(postDataParams));
writer.flush();
writer.close();
os.close();
int responseCode = conn.getResponseCode();
if (responseCode == HttpsURLConnection.HTTP_OK) {
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
sb = new StringBuilder();
String response;
//Reading server response
while ((response = br.readLine()) != null){
sb.append(response);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}
private String getPostDataString(HashMap<String, String> params) throws UnsupportedEncodingException {
StringBuilder result = new StringBuilder();
boolean first = true;
for (Map.Entry<String, String> entry : params.entrySet()) {
if (first)
first = false;
else
result.append("&");
result.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
result.append("=");
result.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
}
return result.toString();
}
Haben Sie Ihre Anwendung getestet? –
Ja, ich habe es getan – user7828682
java.net.SocketException: Sendto fehlgeschlagen: EPIPE (Gebrochenes Rohr). Es zeigt mir diesen Fehler beim Debuggen. – user7828682