0

I have been trying to use call_user_func_array()but dont seem to get it right.

$sql_sentence = "SELECT * FROM test_table WHERE Fag = ? AND (" . $sql_subject . ") AND (" . $sql_grade . ") AND (" . $sql_type . ")";
    $sql = $conn->prepare($sql_sentence);

$allarrays = array_merge(array('ssss'),array($_POST['Fag']),$_POST['subject'],$_POST['Grade'],$_POST['Type']);

//testing to see if it prints out right values of array.
for ($x = 0; $x < count($allarrays); $x++) {
    echo "The number $x is $allarrays[$x] <br>";
} 

call_user_func_array(array($sql, "bind_param"),$allarrays);
$sql->execute();

But I get this error Warning: Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, and it points it to line call_user_func....

When I print out the SQL sentence it looks like this: SELECT * FROM test_table WHERE Fag = ? AND (Subject LIKE ?) AND (Grade LIKE ?) AND (Type LIKE ?) and all array-values are right, and the first array value is 'ssss', and after the first array comes four arrays with different values.

Have I done anything wrong here? Do you need more code?

EDIT: Can you open this question. I found an answer which was different than the similar question! Think it should be printed here.

William82
  • 89
  • 7

1 Answers1

-1

call_user_func_array expects its first argument to be a callable not an array:

mixed call_user_func_array ( callable $callback , array $param_arr )

Which function are trying to call, exactly? mysqli_stmt::bind_param()?

If so, it would need to look something like this:

call_user_func_array(array($stmt, 'bind_param'), array('s', $_POST['Fag']) );
CXJ
  • 4,301
  • 3
  • 32
  • 62
  • I tried this: `call_user_func_array($sql->bind_param(), $allarrays);` but did get error message **Warning: Wrong parameter count for mysqli_stmt::bind_param() ** – William82 Apr 28 '17 at 08:00