Jump to content

MySQLi bind_param() reference


undertaker
Go to solution Solved by undertaker,

Recommended Posts

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();
Link to comment
Share on other sites

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 by undertaker
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.