Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android代码不会使用PHP插入mysql数据库_Php_Android_Mysql - Fatal编程技术网

Android代码不会使用PHP插入mysql数据库

Android代码不会使用PHP插入mysql数据库,php,android,mysql,Php,Android,Mysql,我只是尝试使用php将数据从android代码插入mysql数据库,但代码没有任何作用 register.php: <?php // array for JSON response $response = array(); // check for required fields if (isset($_POST['n'])) { $name = $_POST['n']; $address = $_POST['add']; //$age = $_POST['age'];

我只是尝试使用php将数据从android代码插入mysql数据库,但代码没有任何作用

register.php:

<?php

// array for JSON response
$response = array();

 // check for required fields

if (isset($_POST['n'])) 
{  

$name = $_POST['n'];
$address = $_POST['add']; 
//$age = $_POST['age'];
$phone = $_POST['phone'];
$email = $_POST['e'];  
$bloodgroup = $_POST['bloodgroup'];  


// include db connect class
require_once __DIR__ . '/db_connect.php';

// connecting to db
$db = new DB_CONNECT();

   // mysql inserting a new row
$result = mysql_query("Insert into bloodtb(Name,Address,Phone,Email,Bloodgroup) values

('$name','$address','$phone','$email','$bloodgroup')");

// check if row inserted or not
if ($result) {
    // successfully inserted into database
    $response["success"] = 1;
    $response["message"] = "Product successfully created.";

    // echoing JSON response
    echo json_encode($response);
} else {
    // failed to insert row
    $response["success"] = 0;
    $response["message"] = "Oops! An error occurred.";

    // echoing JSON response
    echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";

// echoing JSON response
echo json_encode($response);
} 
?>

您没有启动线程,因此根本没有执行代码

new Thread(new Runnable() 
{
     @Override
     public void run() 
     {
          new loginAccess().execute();                  
     }
 }).start();
AsyncTask也在不同的线程上执行,所以即使下面的代码也应该执行您的任务

new loginAccess().execute();

是否成功?您是否可以在apache access日志文件中看到您的php脚本被调用?apache/php错误日志文件中有任何消息吗?该活动在设备上运行,但单击“注册”按钮时不会发生任何事情。
Oops!发生的错误
不是告诉您任何事情的错误。当我添加.start()时,请尝试
mysql\u error();然后我得到一个错误:java.lang.ExceptionInInitializeError位于com.blood.bloodconnect.register$1$1.run(register.java:59)位于java.lang.Thread.run(Thread.java:1096),原因是:java.lang.RuntimeException:无法在未在android.os.handler调用Looper.prepare()的线程内创建处理程序。(Handler.java:121)在android.os.AsyncTask$InternalHandler。(AsyncTask.java:421)正如我在回答中所说,AsyncTask在自己的线程中运行,您不需要在另一个线程中启动它,只需使用新的loginAccess().execute();
new loginAccess().execute();