从PHP到android获取错误的数据

时间:2015-09-12 21:23:22

标签: php android

我正在尝试注册模块,我会检查用户是否已经注册。当我通过浏览器运行此脚本时,如果工作完美。但是当我通过android获得响应时,它总是返回-1。但插入仍在发生。我已经完成了检查的所有可能性。有什么建议为什么会发生?

    require_once "config.php";
    $fullname = $_REQUEST['fullname'];
    $email = $_REQUEST['email'];
    $phone_no = $_REQUEST['phone'];
    $status = "pending";
    $password = $_REQUEST['password'];
    $forgot_password = "";
    $options = ['cost' => 11, 'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM) ];
    $password=password_hash($password, PASSWORD_BCRYPT, $options);
    $created = date("Y-m-d H:i:s");
    $modified = $created;  

    $sql="SELECT `id` FROM `Login` WHERE `email`='$email'";
    $result = mysql_query($sql);


    $count=0;
    while ($row = mysql_fetch_array($result)){


        $count++;
     }

     if($count>0){
         //User already registered
         echo "-1";

     }else{

         $q = "INSERT INTO `Login`(`id`,`fullname`,`email`,`phone_no`,`status`,`password`,`forgot_password`,`created`,`modified`) VALUES('','$fullname','$email','$phone_no','$status','$password','$forgot_password','$created','$modified')";
    $s = mysql_query($q);
    if($s){
        $sql="SELECT `id` FROM `Login` WHERE `email`='$email'";
        $result = mysql_query($sql);
        while ($row = mysql_fetch_array($result)){
            $id=$row['id'];
         }

        $sql= "INSERT INTO `profile`(`id`,`firstname`,`lastname`,`gender`,`DOB`,`address`,`state`,`city`,`pincode`,`nationality`,`mobilenumber`,`email`,`scores`) VALUES('$id','$fullname','','','','','','','','','','','')";

        $result = mysql_query($sql);
        if (!$result) {
            //failed to insert
            echo "0";
        }
        else {
            //Success
            echo "1";
        }
    }

     }

   mysql_close($con);

调用的android部分..

new LoadUrl().execute("www.example.com/register.php");


private class LoadUrl extends AsyncTask<String,String,String> {

        protected String doInBackground(String... urls) {
            Log.e("result", "Do In Background");
            UrlLoader urlLoader=new UrlLoader(urls[0]);
            output=urlLoader.load(jsonString);
            return output;
        }

        protected void onPostExecute(String result) {

            String output=result.replaceAll("[\n\t]", "").trim();
            Log.e("Output",output);



            if(output.equals("1")){
                Log.e("Location","Sign Up Success");

            }else if(output.equals("-1")){
                Log.e("Location","Duplicate User");


            }else{
                Log.e("Location","Sign Up Failed");

            }
        }


    }

LOG

09-12 19:54:24.696    4570-4570/com.test.imagecrop E/Email﹕ jrheh@dhjggrd
09-12 19:54:24.696    4570-4570/com.test.imagecrop E/password﹕ svshe
09-12 19:54:24.697    4570-4570/com.test.imagecrop E/confirmPass﹕ vshehehw
09-12 19:54:24.697    4570-4570/com.test.imagecrop E/fullName﹕ hdjrue
09-12 19:54:24.697    4570-4570/com.test.imagecrop E/Phone﹕ 615154846
09-12 19:54:24.699    4570-4643/com.test.imagecrop E/result﹕ Do In Background
09-12 19:54:24.700    4570-4643/com.test.imagecrop E/Location﹕ Set URL
09-12 19:54:24.700    4570-4643/com.test.imagecrop E/Location﹕ Load method
09-12 19:54:24.700    4570-4643/com.test.imagecrop E/Location﹕ [{"attrName":"email","attrVal":"jrheh@dhjggrd"},{"attrName":"password","attrVal":"svshe"},{"attrName":"phone","attrVal":"615154846"},{"attrName":"fullname","attrVal":"hdjrue"}]
09-12 19:54:24.700    4570-4643/com.test.imagecrop E/Location﹕ check1
09-12 19:54:24.702    4570-4643/com.test.imagecrop E/Location﹕ Before Execute
09-12 19:54:27.940    4570-4643/com.test.imagecrop E/Location﹕ After Execute
09-12 19:54:27.941    4570-4570/com.test.imagecrop E/result﹕ -1
09-12 19:54:27.941    4570-4570/com.test.imagecrop E/Output﹕ -1
09-12 19:54:27.941    4570-4570/com.test.imagecrop E/Output Length﹕ 2
09-12 19:54:27.941    4570-4570/com.test.imagecrop E/Location﹕ Duplicate User

0 个答案:

没有答案