Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.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
Php 我只是想验证输入的序列号是否存在于数据库中,在我这样修改代码后,我的AsynTask无法工作。_Php_Android_Android Asynctask - Fatal编程技术网

Php 我只是想验证输入的序列号是否存在于数据库中,在我这样修改代码后,我的AsynTask无法工作。

Php 我只是想验证输入的序列号是否存在于数据库中,在我这样修改代码后,我的AsynTask无法工作。,php,android,android-asynctask,Php,Android,Android Asynctask,我想检查序列号是否已存在于我的表中,但始终通过“检查您的Internet。确保打开Internet或WIFI”来检查我,以下是我的异步代码 class BackGround extends AsyncTask<String, String, String> { @Override protected void onPreExecute() { super.onPreExecute(); dialog = Pro

我想检查序列号是否已存在于我的表中,但始终通过“检查您的Internet。确保打开Internet或WIFI”来检查我,以下是我的异步代码

    class BackGround extends AsyncTask<String, String, String>
    {

    @Override
    protected void onPreExecute()
    {
        super.onPreExecute();
        dialog = ProgressDialog.show(EnterDetailes.this, "",
                "Submitting. Please wait...", true);
        dialog.show();
    }

    @Override
    protected String doInBackground(String... params) {

        String imagename=getStringImage(bitmap);


        String link;
        String data;
        BufferedReader bufferedReader;
        String result;

        try
        {
            data = "?ImageName="+imagename.replace(" ","%20");
            data += "&district="+District.replace(" ","%20");
            data += "&gender="+Gender.replace(" ","%20");
            data += "&city="+City.replace(" ","%20");
            data += "&serialno="+SerialNo.replace(" ","%20");
            // data += "&area="+Area.replace(" ","%20");
            data += "&agencyid="+ID.replace(" ","%20");
            data += "&wareno="+WareNo.replace(" ","%20");
            data += "&latitude="+Latitude.replace(" ","%20");
            data += "&longitude="+Longitude.replace(" ","%20");

            link = "http://www.lorryguru.com/domag/submitdog.php" + data;
            URL url = new URL(link);
            HttpURLConnection con = (HttpURLConnection) url.openConnection();

            bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
            result = bufferedReader.readLine();
            JSONObject jsonObj = new JSONObject(result);
            String query_result = jsonObj.getString("query_result");
            return query_result;
        }
        catch (Exception e)
        {
            return "No Internet";
        }


    }


    @Override
    protected void onPostExecute(String s)
    {
        dialog.hide();

        if(s.equals("Success"))
        {
            s="Uploaded Successfully.";
            serialno.setText("");
            wareno.setText("");
            textViewGpsLat.setText("");
            textViewGpsLng.setText("");
            imageView.setImageDrawable(null);
        }
        else if(s.equals("Already Exists"))
        {
            s="Sorry, serial number already exists";
        }
        else if(s.equals("Fail"))
        {
            s="Sorry, Some query error";
        }
        else
        {
            s="Check Your Internet. Make sure you turn on the Internet or WIFI";
        }
        Toast.makeText(ctx, s, Toast.LENGTH_LONG).show();
    }
}
类后台扩展异步任务
{
@凌驾
受保护的void onPreExecute()
{
super.onPreExecute();
dialog=ProgressDialog.show(输入detailes.this,“,
“正在提交。请稍候…”,正确);
dialog.show();
}
@凌驾
受保护的字符串doInBackground(字符串…参数){
字符串imagename=getStringImage(位图);
串链;
字符串数据;
BufferedReader BufferedReader;
字符串结果;
尝试
{
data=“?ImageName=“+ImageName.replace”(“,“%20”);
数据+=“&district=“+district.replace”(“,“%20”);
数据+=”&gender=“+gender.replace”(“,“%20”);
数据+=“&city=“+city.replace”(“,“%20”);
数据+=”&serialno=“+serialno.replace”(“,“%20”);
//数据+=“&area=“+area.replace”(“,“%20”);
数据+=”&agencyid=“+ID.replace”(“,“%20”);
数据+=”&wareno=“+wareno.replace”(“,“%20”);
数据+=“&latitude=“+latitude.replace”(“,“%20”);
数据+=“&longitude=“+longitude.replace”(“,“%20”);
链接=”http://www.lorryguru.com/domag/submitdog.php“+数据;
URL=新的URL(链接);
HttpURLConnection con=(HttpURLConnection)url.openConnection();
bufferedReader=新的bufferedReader(新的InputStreamReader(con.getInputStream());
结果=bufferedReader.readLine();
JSONObject jsonObj=新的JSONObject(结果);
字符串查询结果=jsonObj.getString(“查询结果”);
返回查询结果;
}
捕获(例外e)
{
返回“没有互联网”;
}
}
@凌驾
受保护的void onPostExecute(字符串s)
{
dialog.hide();
如果(s.equals(“成功”))
{
s=“已成功上载。”;
serialno.setText(“”);
wareno.setText(“”);
text视图gpslat.setText(“”);
textViewGpsLng.setText(“”);
imageView.setImageDrawable(空);
}
否则,如果(s.equals(“已存在”))
{
s=“对不起,序列号已经存在”;
}
否则,如果(s.equals(“Fail”))
{
s=“对不起,有些查询错误”;
}
其他的
{
s=“检查您的互联网。确保打开互联网或WIFI”;
}
Toast.makeText(ctx,s,Toast.LENGTH_LONG).show();
}
}
我的PHP代码如下

       <?php
       require 'init.php';
       date_default_timezone_set('Asia/Calcutta');
       $date    = date('Y-m-d H:i:s');

       $serialno = $_REQUEST["serialno"];

       $sql = "SELECT * FROM dogs_details WHERE serial_no='".$serialno."' ";
       $res = $db->prepare($sql);
       $res->execute();
       $count =  $res->rowCount();
       if($count>0)
       {
       echo '{"query_result":"Already Exists"}';    
       }
       else{


      $district     = $_REQUEST["district"];
      $city         = $_REQUEST["city"];
      $gender   = $_REQUEST["gender"];
      $serialno     = $_REQUEST["serialno"];
      $agency_id    = $_REQUEST["agencyid"];
      $wareno   = $_REQUEST["wareno"];
      $before   = $_REQUEST["ImageName"];
      $latitude     = $_REQUEST["latitude"];
      $longitude    = $_REQUEST["longitude"];
      $path         = "before_dog/".uniqid().".jpg";
      $actualpath = "http://www.lorryguru.com/domains/dogs/$path";

      $db->beginTransaction();
      $query    = $db->prepare("insert into dogs_details(district,city,gender,serial_no,ware_no,latitude,longitude,posted_on,before_dog,agency_id) VALUES ( ?,?, ?, ?, ?, ?, ?, ?, ?, ?)");

    $query->bindValue(1, $district );
    $query->bindValue(2, $city);
    $query->bindValue(3, $gender);
    $query->bindValue(4, $serialno);
    $query->bindValue(5, $wareno);
    $query->bindValue(6, $latitude);
    $query->bindValue(7, $longitude);
    $query->bindValue(8, $date);
    $query->bindValue(9, $actualpath);
    $query->bindValue(10, $agency_id);



    try{
        $query->execute();
        file_put_contents($path,base64_decode($before));
        $db->commit();
        echo '{"query_result":"Success"}';
        }
        catch(PDOException $e){
        die($e->getMessage());
        $db->rollBack();
        echo '{"query_result":"Fail"}';
    }

}

调试并检查您得到的“s”值。调试并检查您得到的“s”值。