简体   繁体   English

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

[英]Problem handling data to php with POST method

I'm working on 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.我使用 Android Studio 开发了它,但在使用 POST 方法将用户信息处理到 php 文件时遇到了一些问题。

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:这是我的Java代码:

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 代码:

<?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);
?>

Assuming everything else is correct, your parameter type specification in the bind call has an i (integer) that doesn't match any parameter.假设其他一切都正确,则绑定调用中的参数类型规范具有与任何参数都不匹配的i (整数)。 For 3 string parameters, you'll want to use sss :对于 3 个字符串参数,您需要使用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?查看php-mysql脚本失败时如何获取详细的错误报告?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM