douyong8801 2017-09-08 02:39
浏览 125
已采纳

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

I'm getting these warnings from web host which contains my database. I'm trying to get an android app developed in Android studio to send data from a Register user activity to a database. I think I'm having a PHP Script error..

Below is my PHP code for registering user:

<?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条回答 默认 最新

  • douxiong3234 2017-09-08 02:49
    关注

    You have check for errors:-

    <?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
    ", 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);
        }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 速度位置规划实现精确定位的问题
  • ¥15 代码问题:df = pd.read_excel('c:\User\18343\Desktop\wpsdata.xlxs')路径读不到
  • ¥15 为什么视频算法现在全是动作识别?
  • ¥15 编写一段matlab代码
  • ¥15 用Python做岩石类别鉴定软件
  • ¥15 关于调取、提交更新数据库记录的问题
  • ¥15 之前删了盘从下vs2022遇见这个问题 搞了一整天了
  • ¥15 从Freecad中宏下载的DesignSPHysics,出现如下问题是什么原因导致的(语言-python)
  • ¥30 notepad++ 自定义代码补全提示
  • ¥15 MATLAB有限差分法解一维边值问题