i have checked my code 100 times but didn't find any solution for this i have already checked so many websites to find it's solution but didn't find anything. This is an signup system i am trying to make it fully easiest signup system i mean easiest way to use my functions everywhere in my website. I have created a function called database in which i have created a switch statements that will create, connect, update, delete the user data from database by just one function but i am getting an error at Bind_param.
Uncaught ArgumentCountError: The number of elements in the type definition string must match the number of bind variables
$query = "INSERT INTO $table (";
foreach ($tableNames as $key => $value) {
$query .= "$key, ";
}
$query = substr($query, 0, -2);
$query .= ") VALUES (";
$j = 0;
foreach ($tableNames as $key1 => $value2) {
for ($a=0; $a < $j; $a++) {
++$j;
}
$query .= "?, ";
}
$query = substr($query, 0, -2);
$query .= ")"; //correct working
// echo $query;
$stmt = $conn->prepare("$query");
$fieldsNumb = "";
$l = 0;
foreach ($tableNames as $keyss => $valuess) {
for ($k=0; $k < $l; $k++) {
++$l;
}
$fieldsNumb .= "s";
}
$fields = "";
foreach ($tableNames as $keys => $values) {
$fields .= "$"."$keys".",";
}
// echo $fields;
$fields = substr($fields, 0, -2);
// echo $query;
$stmt->bind_param("$fieldsNumb", $fields);
// set parameters and execute
$stmt->execute();
msg("", "success", "Signedup success");
$stmt->close();
$conn->close();