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?