不能从数据库插入到本地主机使用php
问题描述:
我想存储数据库中存在的本地主机,我的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>
敬酒消息说像未定义指数
和数据库更新到无文本空白框。
答
尝试删除html
标签只留下PHP:
<?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();
?>
127.0.0.1/Sandbox/signup.php应该是本地主机URL从模拟器 – Rasel
仍然没有成功 – Developer