0

I am getting a PHP Warning:

mysqli_stmt_bind_param() expects parameter 2 to be string, array given. The line in question is: mysqli_stmt_bind_param($stmt, $types, $values);

I guess this is because $types and $values are arrays containing the bind data, the problem is I don't know how to get them from the array into the bind command.

Any help on this using procedural based code?

   if (isset($_POST['submit'])) {

    $query = "SELECT profile FROM profiles WHERE state != 9 AND blocked = 0";
    $conditions = [];
    $lookingfor = [];

// Validate minimum age
    if ((isset($_POST['minimumage'])) and (preg_match('/^\d{2}$/', $_POST['minimumage']))) {
        $conditions['minage >= ?'] = ['i', $_POST['minimumage']];
        $lookingfor[] = "Minimum age " . $_POST['minimumage'];
    }

// Validate maximum age
    if ((isset($_POST['maximumage'])) and (preg_match('/^\d{2}$/', $_POST['maximumage']))) {
        $conditions['maxage <= ?'] = ['i', $_POST['maximumage']];
        $lookingfor[] = "Maximum age " . $_POST['maximumage'];
    }

    if (!empty($lookingfor)) {
        foreach ($lookingfor as $var) {
            echo "<li>" . $var . "</li>";
        }
    }

    $where_clauses = $types = $values = [];

    if (!empty($conditions)) {
        foreach ($conditions as $clause => $condition) {
            $where_clauses[] = $clause;
            list($types[], $values[]) = $condition;
        }
        $query .= " AND ";
        $query .= join(" AND ", $where_clauses);
    }

    echo $query;

    $stmt = mysqli_prepare($sql_connect, $query);

    if (!empty($conditions)) {
        mysqli_stmt_bind_param($stmt, $types, $values);
    }
    mysqli_stmt_execute($stmt);
    mysqli_stmt_store_result($stmt);
    mysqli_stmt_fetch($stmt);

    if (mysqli_stmt_num_rows($stmt) > 0) {
        echo "Found " . mysqli_stmt_num_rows($stmt) . " profiles which match this criteria";
    }
}
  • Perhaps `implode();` is what you need? – Epodax Aug 11 '15 at 10:25
  • Is it as simple as... mysqli_stmt_bind_param($stmt, implode('', $types), implode('', $values)); –  Aug 11 '15 at 10:29
  • The thread "Bind multiple parameters into mysqli query" is using OOP, which I am not, therefore I don't consider it a duplicate. –  Aug 11 '15 at 10:33

0 Answers0