错误:“警告:mysqli_stmt_bind_param()”

时间:2019-06-08 05:52:54

标签: php mysql sql mysqli

我想将会员计划添加到我的网站:https://hosteyme.ga/mobile.php(建议使用移动设备来访问它) 您会发现该站点可以正常运行,但是现在请检查'https://hosteyme.ga/mobile.php?affiliate=19060123'弹出错误!

  

错误:“警告:mysqli_stmt_bind_param():变量数量不正确   匹配准备好的语句中的参数数量(第12行)

mobile.php代码:

<?php

session_start();
require_once "config.php";
$affiliate = "";

if ($_SERVER["REQUEST_METHOD"] == "GET") {
    $affiliate = $_GET['affiliate'];
    $sql = "SELECT id, affiliate, click, signup FROM users WHERE affiliate = $affiliate";
    if ($stmt = mysqli_prepare($link, $sql)) {
        // Bind variables to the prepared statement as parameters
        mysqli_stmt_bind_param($stmt, "ssss", $param_id, $param_affiliate, $param_click, $param_signup);

        // Set parameters
        $param_affiliate = $affiliate;

        // Attempt to execute the prepared statement
        if (mysqli_stmt_execute($stmt)) {
            // Store result
            mysqli_stmt_store_result($stmt);

            // Check if affiliate exists
            if (mysqli_stmt_num_rows($stmt) == 1) {
                // Bind result variables
                mysqli_stmt_bind_result($stmt, $id, $affiliate, $click, $signup);
                mysqli_query("UPDATE users SET click = click + 1 WHERE affiliate = $affiliate");
                session_start();

                // Store data in session variables
                $_SESSION['affiliate'] = $affiliate;
            }
        }
    }
}

$_SESSION['affiliate']用于跟踪会员链接。 mysqli_query("UPDATE users SET click = click + 1 WHERE affiliate = $affiliate")用于在用户点击会员链接时添加1次点击。

如何解决错误?

1 个答案:

答案 0 :(得分:-2)

通常在“字符串”或“ s”中输入

    mysqli_stmt_bind_param($stmt, "ssss", $param_id, $param_affiliate, $param_click, $param_signup);

如果为数字等,则可能返回假值。对于数字值,应使用“ i”

    mysqli_stmt_bind_param($stmt, "isss", $param_id, $param_affiliate, $param_click, $param_signup);

我觉得第一个结果(id)是数字