duanleixun2439 2018-12-03 18:04
浏览 45
已采纳

使用POST方法将数据处理到php的问题

I'm working on a project which is an application that registers users in a database of a domain I have. I developed it using Android Studio, and I'm having some problems handling the users info to the php file using the POST method. The main problem I have is that my app returns a success while transfering the data to the database, but when I look at it it's empty. Here's my Java code:

package com.test.application;

import com.android.volley.Response;
import com.android.volley.toolbox.StringRequest;

import java.util.HashMap;
import java.util.Map;

public class RegisterRequest extends StringRequest {

private static final String REGISTER_REQUEST_URL="http://www.mywebsite.com/Register.php";
private Map<String,String> params;
public RegisterRequest(String user, String password, String email, Response.Listener<String> listener){
    super(Method.POST, REGISTER_REQUEST_URL, listener, null);
    params = new HashMap<>();
    params.put("name", user);
    params.put("password", password);
    params.put("useremail", email);
}

@Override
public Map<String, String> getParams() {
    return params;
}
}

and here's my PHP code that recieves the data:

<?php
    $con = mysqli_connect("bbdd.mywebsite.com", "user", "password", "database");

    $Username = $_POST["name"];
    $Password = $_POST["password"];
    $UserEmail = $_POST["useremail"];
    $statement = mysqli_prepare($con, "INSERT INTO AccountsInfo (Username, Password, UserEmail) VALUES (?, ?, ?)");
    mysqli_stmt_bind_param($statement, "ssis", $Username, $Password, $UserEmail);
    mysqli_stmt_execute($statement);

    $response = array();
    $response["success"] = true;  

    echo json_encode($response);
?>

Any help will be appreciated. Thanks in advanced

  • 写回答

1条回答 默认 最新

  • dqeonr8554 2018-12-03 18:20
    关注

    Assuming everything else is correct, your parameter type specification in the bind call has an i (integer) that doesn't match any parameter. For 3 string parameters, you'll want to use sss:

    mysqli_stmt_bind_param($statement, "sss", $Username, $Password, $UserEmail);
    

    You should enable error reporting so that things don't just fail silently. See how to get a detailed error report when a php-mysql script fails?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境