-1
嘿,夥計們我試圖使註冊頁面使用mysqli和PHP的後端和Java的前端。我的PHP連接文件工作文件,即使我插入數據以及當我試圖插入數據使用Android應用程序它不插入,甚至它不顯示任何錯誤日誌。Android的Mysql連接錯誤
我是在android的Begginer。請原諒,如果你發現任何錯誤。
這裏是我的插入文件
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);
這是我的註冊頁面
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;
}
}
這裏是我的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();
}
你調試了你的應用程序嗎? –
是的,我已經做到了 – user7828682
java.net.SocketException:發送失敗:EPIPE(Broken pipe)。它在調試時向我顯示這個錯誤。 – user7828682