Hey les gars, je suis en train de faire une page d'enregistrement en utilisant mysqli et php pour backend et java pour le front end. Mon fichier de connexion PHP fonctionne même si j'ai inséré des données quand j'ai essayé d'insérer des données à l'aide de l'application Android. Il ne l'insère pas et ne montre aucune erreur dans le journal.Android Mysql erreur de connexion
Je suis Begginer dans android. S'il vous plaît pardonner si vous avez trouvé une erreur.
Voici mon Insérer un fichier
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);
Voici mon inscription Page
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;
}
}
Voici mon fichier HttpURLConnection
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();
}
Avez-vous débogué votre application? –
Ouais je l'ai fait – user7828682
java.net.SocketException: sendto a échoué: EPIPE (Broken pipe). Il me montre cette erreur lors du débogage. – user7828682