Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.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 httppost Android,值不会传递到数据库以创建用户_Php_Android_Sql_Http Post - Fatal编程技术网

Php httppost Android,值不会传递到数据库以创建用户

Php httppost Android,值不会传递到数据库以创建用户,php,android,sql,http-post,Php,Android,Sql,Http Post,我已经成功地使用httppost从javaandroid代码通过php到mysql创建了一个身份验证。但是,我在创建新用户时遇到问题。我已经检查了其他用户的多篇帖子,我认为它看起来不错。此外,我还创建了一个简单的html表单来测试新用户的php创建,这也很有效 如有任何想法,将不胜感激。下面是我的java代码和PHP。谢谢 try { // create new array list nameValuePairs = new ArrayLi

我已经成功地使用httppost从javaandroid代码通过php到mysql创建了一个身份验证。但是,我在创建新用户时遇到问题。我已经检查了其他用户的多篇帖子,我认为它看起来不错。此外,我还创建了一个简单的html表单来测试新用户的php创建,这也很有效

如有任何想法,将不胜感激。下面是我的java代码和PHP。谢谢

    try {
            // create new array list
            nameValuePairs = new ArrayList<NameValuePair>();

            // place them in an array list
            nameValuePairs.add(new BasicNameValuePair("username", user));
            nameValuePairs.add(new BasicNameValuePair("password", pass));

            // add array list to http post
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            // assign executed form container to response
            response = httpclient.execute(httppost);

            // check status code,
            if (response.getStatusLine().getStatusCode() == 200) {
                // assign response entity to htpp entitiy
                entity = response.getEntity();

                // chekc if entity is not null
                if (entity != null) {

                    Log.i("RESPONSE",EntityUtils.toString(entity));

                    Intent intent = new Intent(CreateAccount.this,
                            MainActivity.class);
                    startActivity(intent);

                    // }

                    // display a taost saying login was a success
                    Toast.makeText(CreateAccount.this, user,
                            Toast.LENGTH_SHORT).show();
                    // }

                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            // display toast when there is a connection error
            Toast.makeText(getBaseContext(), "ConnectionError",
                    Toast.LENGTH_SHORT).show();
        }

发布时,值被称为“用户名”和“密码”,而服务器检查“用户”和“通过”。你必须使用相同的钥匙

    //get form data

$user = mysql_real_escape_string($_POST['user']);

$pass = mysql_real_escape_string($_POST['pass']);

echo "INSERT INTO androidlogin (user, pass) VALUES ('$user','$pass')";

//insert data
$insert = mysql_query("INSERT INTO androidlogin (user, pass) VALUES  ('$user','$pass')");
if($insert){
$arr2 = array("user" => $user, "pass" => $pass);
echo json_encode($arr2);

}