undertaker Posted August 12, 2013 Share Posted August 12, 2013 I am trying to pass several parameters dynamically to the bind_param() function. Here is the error i receive: Warning: Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, value given $con = new mysqli('localhost',USER,PASS,DBS); if(mysqli_connect_errno()) { error(mysqli_connect_errno()); } $con -> set_charset("utf8"); /*inside*/ $type=''; $query='SELECT bugID FROM bug'; if(!empty($_GET['cena'])) { $build[]='uCena=?'; $type.='i'; $val[]=$_GET['cena']; } if(!empty($_GET['popust'])) { $build[]='uPopust=?'; $type.='i'; $val[]=$_GET['popust']; } if(!empty($build)) { echo $query .= ' WHERE '.implode(' AND ',$build); } $new = array_merge(array($type),$val); foreach($new as $key => $value) { $tmp[$key]=&$new[$key]; } echo '<br/><br/>'; foreach ($new as $new ){ echo "$new<br/>"; } if ($count = $con->prepare($query)) { call_user_func_array(array($count,'bind_param'),$tmp); $count->execute(); $cres = $count->fetch_row(); $count -> close(); } else error($con->error); /*inside*/ $con -> close(); Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted August 12, 2013 Share Posted August 12, 2013 you already have a thread on this forum for this problem, where someone showed what the code needed to be. you seem to be just randomly throwing code up against the wall to see what sticks. Quote Link to comment Share on other sites More sharing options...
undertaker Posted August 12, 2013 Author Share Posted August 12, 2013 (edited) I am sorry, i havent noticed you changed my code there. Thought it was just a quote of my post.I tried to rewrite the code and present my problem better in a new post since you told me the previous looked like piece of *. Edited August 12, 2013 by undertaker Quote Link to comment Share on other sites More sharing options...
Solution undertaker Posted August 12, 2013 Author Solution Share Posted August 12, 2013 Solved here: http://forums.phpfreaks.com/topic/281071-mysqli-dynamic-bind-param-parameters/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.