I am experiencing the following error.
Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables
How to fix the issue?
Authenticate.php
<?php
require_once "config.php";
session_start();
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
echo $_POST['username'];
echo $_POST['password'];
$error = '';
echo "Submit clicked";
if (empty($_POST['username']) || empty($_POST['password'])) {
echo "Username or Password is invalid";
echo "Still haven't got data";
}else{
$username = $_POST['username'];
$password = $_POST['password'];
$conn = $link;
$query = "SELECT username, password, data FROM mathbglogin WHERE username = '$username' and password = '$password'";
$stmt = $conn->prepare($query);
$stmt->bind_param("sss", $username, $password, $data);
$stmt->execute();
$stmt->bind_result($username, $password, $data);
$stmt->store_result();
if($stmt->fetch()){
$_SESSION['username'] = $username;
$_SESSION['data'] = $data;
echo $username, $data;
header("location: welcome.php");
mysqli_close($conn);
echo "Done!";
}else{
echo "Unsuccessful";
}
}
?>
config.php
<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_NAME', 'users');
$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
?>
What I get is:
123321Submit clicked
Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables in D:\Apps\XAMPP\htdocs\StefanMath - Copy\LoginAuthenticate.php on line 22
Unsuccessful
Keep in mind that 123321 is the dummy test and password.
What I have tried:
I have tried changing the number of the statements but it doesn't work.