Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/369.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
Java 我所需要做的就是发布3个值!Android到PHP服务器脚本_Java_Php_Android_Mysql - Fatal编程技术网

Java 我所需要做的就是发布3个值!Android到PHP服务器脚本

Java 我所需要做的就是发布3个值!Android到PHP服务器脚本,java,php,android,mysql,Java,Php,Android,Mysql,android设备上的代码是: public JSONObject getJSONFromUrl(String url, List<NameValuePair> params) { // Making HTTP request try { // defaultHttpClient DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost http

android设备上的代码是:

public JSONObject getJSONFromUrl(String url, List<NameValuePair> params) {


    // Making HTTP request
    try {
        // defaultHttpClient
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);
        httpPost.setEntity(new UrlEncodedFormEntity(params));

        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "n");
        }
        is.close();
        json = sb.toString();
        Log.e("JSON", json);
    } catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }

    // try parse the string to a JSON object
    try {
        jObj = new JSONObject(json);
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }

    // return JSON String
    return jObj;
    }
其中storeUser是:

    public function storeUser($name, $email, $password) {

    $result = mysql_query("INSERT INTO users(unique_id, name, email, encrypted_password, salt, created_at) VALUES('$uuid', '$name', '$email','$encrypted_password', '$salt', NOW())");

    }
这个过程是有效的,会向android设备发送一条消息,但细节不清楚 插入MySQL数据库

我只想从android设备发布详细信息,并将其插入我服务器上的MySQL数据库

谁知道为什么会这样,我做错了什么

$name = $_POST['name'];
$name = $_POST['email'];
$name = $_POST['password'];
这显然是错误的。将变量更改为
$email
$password


此外,停止使用mysql_查询,因为它正在变得越来越强大。使用或代替。

我从上面找出了我的代码的错误

java/android代码中传递给httppost的url不能作为我使用的api的简单地址,我尝试了www.domain.com/index.php?用“?”号。添加此代码使代码正常工作

我只是回到了最基本的部分,看看是什么让一篇文章如此精彩


这里是对维基百科上的文章的参考,它帮助我找出了http POST的组成部分,警告您的代码容易受到sql注入攻击。如何防止这种攻击的教程?
$name = $_POST['name'];
$name = $_POST['email'];
$name = $_POST['password'];