-3

I want to add an affiliate program to my website: https://hosteyme.ga/mobile.php (recommend to use mobile to visit it) You will find that the site works normal, but now check out 'https://hosteyme.ga/mobile.php?affiliate=19060123' The error pop up!

Error: 'Warning: mysqli_stmt_bind_param(): Number of variables doesn't match number of parameters in prepared statement' (on line 12)

mobile.php code:

<?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'] is used to track the affiliate link. mysqli_query("UPDATE users SET click = click + 1 WHERE affiliate = $affiliate") is used to add 1 click when someone click the affiliate link.

How to solve the error?

Dharman
  • 30,962
  • 25
  • 85
  • 135
HosteyMega
  • 25
  • 7
  • Make sure all 4 parameters are using `string` types. For example, if `$param_id` is an `integer` and not a `string`, the second type parameter should be **isss** instead of **ssss**: https://www.php.net/manual/en/mysqli-stmt.bind-param.php#refsect1-mysqli-stmt.bind-param-parameters –  Jun 08 '19 at 06:05
  • 2
    Your statement does not contain *any* placeholders, much less four of them. I’m not sure what parameters you think you’re binding there. – deceze Jun 08 '19 at 06:09

1 Answers1

-2

Usually "string" or "s" in:

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

can return false value if be numbers or etc. you should use "i" for numbric values

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

i feel the first result (id) is number

EchoDino
  • 35
  • 1
  • 10