我想存儲數據庫中存在的本地主機,我的android和php代碼似乎工作正常,但它不寫入數據到數據庫。不能從數據庫插入到本地主機使用php
這裏是我的Android doInBackground
@Override
protected String doInBackground(String... params) {
String type= params[0];
String name;
String user_name;
String user_phone;
String user_address;
String password;
String login_url = "http://192.168.1.5/Sandbox/signup.php";
String register_url = "http://192.168.1.5/Sandbox/Register.php";
if (type.equals("login")){
try {
Log.d("inside", "doInBackground: ");
password = params[2];
name= params[1];
URL url = new URL(login_url);
Log.d("middle", "doInBackground: ");
HttpURLConnection http = (HttpURLConnection) url.openConnection();
http.setRequestMethod("POST");
http.setDoOutput(true);
http.setDoInput(true);
Log.d("middle", "doInBackground: ");
OutputStream outputstream = http.getOutputStream();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputstream, "UTF-8"));
String post_data = URLEncoder.encode("name"+"UTF-8")+"="+URLEncoder.encode(name+"UTF-8")+"&"+URLEncoder.encode("password"+"UTF-8")+"="+URLEncoder.encode(password+"UTF-8");
Log.d("middle", "doInBackground: ");
bufferedWriter.write(post_data);
bufferedWriter.flush();
bufferedWriter.close();
outputstream.close();
InputStream inputstream = http.getInputStream();
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(inputstream,"iso-8859-1"));
result="";
String line="";
while ((line=bufferedreader.readLine())!=null){
result+=line;
}
bufferedreader.close();
inputstream.close();
http.disconnect();
inputstream.close();
Log.d("leaving","doInBackground: ");
return "Registration Successful";
} catch (Exception e) {
e.printStackTrace();
}
}
這裏是我的PHP文件
<html lang="en">
<title>LOGIN</title>
<body>
<?php
require "Conn.php";
$name= $_POST["name"];
$password = $_POST["password"];
$mysql_qry="insert into user_table values('$name','$password')";
if (mysqli_query ($con,$mysql_qry)){
echo "Insert Success";
}
else{
echo "ERROR!".mysqli_error($con);
}
$con->close();
?>
</body>
</html>
敬酒消息說像未定義指數
和數據庫更新到無文本空白框。
127.0.0.1/Sandbox/signup.php應該是本地主機URL從模擬器 – Rasel
仍然沒有成功 – Developer