【问题标题】:"Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in" [duplicate]“警告:mysqli_stmt_bind_param() 期望参数 1 为 mysqli_stmt,布尔值” [重复]
【发布时间】:2017-09-08 02:39:30
【问题描述】:

我从包含我的数据库的网络主机收到这些警告。我正在尝试让在 Android Studio 中开发的 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);
?>

【问题讨论】:

  • echo mysqli_error($con); 查看具体的SQL错误。也尝试粘贴您的表架构。
  • @AlivetoDie 我现在会 :)
  • @AlivetoDie 好的,我明白了。我现在纠正了它,错误已经消失了,只是看看我的 android 代码现在是否可以相应地工作:D,多亏了你,网络请求现在没有显示任何错误或警告。
  • @AlivetoDie 但是安卓部分仍然无法正常工作.. :(
  • 像这样更改消息部分:-if(mysqli_stmt_execute($statement)){ $response["success"] = true; }else{ $response["success"] = false; } echo json_encode($response);(我根据您原来的更改)并检查您的现在

标签: php sql mysqli


【解决方案1】:

您已检查错误:-

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多