BuildMyWeb Posted July 28, 2015 Share Posted July 28, 2015 i cannot seem to figure out how to pass my array of values here. i get the following error(s): Warning: Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, value given in ... on line 54 Fatal error: Uncaught exception 'ReflectionException' with message 'Invocation of method mysqli_stmt::bind_param() failed' in ... ReflectionMethod->invokeArgs(Object(mysqli_stmt), Array) #1 {main} thrown in ... $action = clean_string( $_POST['action'] ); $user_select = $_POST['user_select']; if( empty($action) ) { header('Location: ' . C_REF . '?msg_raw=act'); exit(); } else { $in = '?'; $types = 'si'; $arr_values = array($action, $user_select[0]); for( $i=2; $i < count($user_select)+1; $i++ ) { $in .= ', ?'; $types .= 'i'; $arr_values[] = $user_select[$i-1]; } array_unshift($arr_values, $types); $sql = "UPDATE users SET status = ? WHERE id IN (" . $in . ")"; $stmt = $db_connect->prepare($sql); $ref = new ReflectionClass('mysqli_stmt'); $method = $ref->getMethod("bind_param"); $method->invokeArgs($stmt,$arr_values); $stmt->execute(); } // close else Link to comment https://forums.phpfreaks.com/topic/297527-prepared-statement-with-dynamic-of-values/ Share on other sites More sharing options...
BuildMyWeb Posted July 28, 2015 Author Share Posted July 28, 2015 ive been working on this off and on for two days. finally figured it out. for anyone who references this thread, here is the solution: function refValues($arr){ if (strnatcmp(phpversion(),'5.3') >= 0) //Reference is required for PHP 5.3+ { $refs = array(); foreach($arr as $key => $value) $refs[$key] = &$arr[$key]; return $refs; } return $arr; } $arr_values = refValues($arr_values); http://stackoverflow.com/questions/16120822/mysqli-bind-param-expected-to-be-a-reference-value-given Link to comment https://forums.phpfreaks.com/topic/297527-prepared-statement-with-dynamic-of-values/#findComment-1517596 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.