“警告:mysqli_stmt_bind_param()要求参数1为mysqli_stmt,布尔值在”

时间:2017-09-08 02:39:31

标签: php android sql database

我从包含我的数据库的网络主机收到这些警告。我正在尝试在Android工作室中开发一个Android应用程序,以便将数据从注册用户活动发送到数据库。我想我有一个PHP脚本错误..

以下是我注册用户的PHP代码:

<?php
$con = mysqli_connect("localhost", "user", "pass", "db");

if (isset($_POST["name"], $_POST["email"], $_POST["username"], $_POST["password"])) 
{
$name =     $_POST["name"];
$email =    $_POST["email"];
$username = $_POST["username"];
$password = $_POST["password"];
}

$statement = mysqli_prepare($con, "INSERT INTO user (name, username, email, password) VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($statement, "siss", $name, $username, $email, $password);
mysqli_stmt_execute($statement);

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

echo json_encode($response);
?>

The Register request URL used in android studio..

Android Logcat result during the error

1 个答案:

答案 0 :(得分:0)

您已检查错误: -

<?php
    //comment these two lines when code started working fine
    error_reporting(E_ALL);
    ini_set('display_errors',1);

    $con = mysqli_connect("localhost", "id2833909_split421", "pass123", "id2833909_splitw");

    /* check connection */
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }

    if (isset($_POST["name"], $_POST["email"], $_POST["username"], $_POST["password"])) {
        $name =     $_POST["name"];
        $email =    $_POST["email"];
        $username = $_POST["username"];
        $password = $_POST["password"];
        $statement = mysqli_prepare($con, "INSERT INTO `user` (`name`, `username`, `email`, `password`) VALUES (?, ?, ?, ?)");
        mysqli_stmt_bind_param($statement, "ssss", $name, $username, $email, $password); // i need to be s
        $response = array();
        if(mysqli_stmt_execute($statement)){
            $response["message"] = "success";  
        }else{
            $response["message"] = "error";  
        }
        echo json_encode($response);
    }
?>