Jump to content

Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]


cypher86

Recommended Posts

$params = array();
	$type=array();
	$fragments = array();

	while (list($chiave,$val) = each($_POST)){
		if($val!=""){
			$fragments[] = $chiave." = ?";
			//echo $chiave;
			if($chiave=="ritiro" or $chiave=="data")
				$params[] = normalToDbDate($val);
			else
				$params[] = $val;
			if($chiave=="legale")
				$type[]='i';
			else
				$type[]='s';
		}
	}

	$prova=implode("",$type);
	foreach($params as $param)
		echo "<p>".$param."</p>";
	//echo "val(".count($params).")-->".implode(',',$params);
	//echo "type(".strlen($prova).")-->".implode("",$type);
	$sql = $db->prepare("..... AND ".implode(" AND ", $fragments));
	array_unshift($params,$prova)
	call_user_func_array( array( $sql, 'bind_param' ),$params);
	//$sql->bind_param($prova,$params);
	$sql->execute();
      

 

hi all, with the tructure above i've tried to implement the cration of a dynamic query for a search form. i debugged with echoes and che numbers of bind_param and the those in the prepared statement match in sense that count($params)=strlen($prova). having said that i get this error:

 

Warning: call_user_func_array() expects parameter 2 to be array, integer given in

 

and no results are shown to me even when the filter match.

Link to comment
Share on other sites

foreach($params as $param)
		echo "<p>".$param."</p>";

 

$params seems an array (at list for this loop).

so

call_user_func_array( array( $sql, 'bind_param' ),$params);

should act like

$sql->bind_param('iiiiss....',$par1,$par2,.......)

 

or am i wrong?

 

edit: according to http://php.net/manual/en/function.array-unshift.php it returns an array but at the head of the array is added the second, third,... param

Link to comment
Share on other sites

since you are not setting the return value of array_unshift to $params, I do agree that the $params value should still be an array, I would try outputting either a var_dump or a print_r just after using the array_unshift function and before using the call_user_func_array function

Link to comment
Share on other sites

the form i'm working on is the following:

<fieldset id="ricerca" name="ricerca">
<legend>Ricerca</legend>
<form name="form_notifiche" id="form_notifiche" action="notifiche.php?cerca=true" method="POST">

	<input type="hidden" id="id" name="id" value="" />
	<div><label>Data: </label><input type="text" name="data" id="data" /><input type="button" value="..." onclick="return showCalendar('data', '%d/%m/%Y');">(gg/mm/aaaa)</div>
	<div><label>Numero: </label><input type="text" name="numero" id="numero" /></div>
	<div><label>Parti: </label><input type="text" name="parti" id="parti" /></div>
	<div><label>Legale: </label><select id="legale" name="legale" ><option value="16">Alberto</option><option value="2">Alberto</option><option value="15">Alberto</option><option value="9">cypher</option>.......</select></div>

	<div><label>Atto: </label><input type="text" name="atto" id="atto" /></div>
	<div><label>Data Ritiro: </label><input type="text" name="ritiro" id="ritiro" /><input type="button" value="..." onclick="return showCalendar('ritiro', '%d/%m/%Y');">(gg/mm/aaaa)</div>
	<div><input type="submit" value="Cerca"></div>
</form>
</fieldset>

Link to comment
Share on other sites

typically for a search form, the user types in the search criteria, and a SELECT query using the LIKE clause is used to pull results from the database and display the results to the user.. there are many tutorials out there that can get your started if you are not sure on how to approach this.

Link to comment
Share on other sites

with dates you will use a conditional statement in your query, do you want to pull dates that are greater than or less than the date specified by the user. An integer will need to come back with an equivalent match, what exactly do you mean by your question?

Link to comment
Share on other sites

Well as AyKay47 pointed out, you were missing a semi-colon off the end of your array_unshift() call, which means the code you posted would never work. Can you post the exact code you're running when you're receiving the error?

Link to comment
Share on other sites

$params = array();
	$type=array();
	$fragments = array();

	//while (list($chiave,$val) = each($_POST)){
	//	echo $chiave.":".$val."<br>";
	//}



	while (list($chiave,$val) = each($_POST)){
		if($val!=""){
			$fragments[] = $chiave." = ?";
			//echo $chiave;
			if($chiave=="ritiro" or $chiave=="data")
				$params[] = normalToDbDate($val);
			else
				$params[] = $val;
			if($chiave=="legale")
				$type[]='i';
			else
				$type[]='s';
		}
	}

	$query = "....... AND ".implode(" AND ", $fragments);
	echo $query;
	$prova=implode("",$type);
	foreach($params as $param)
		echo "<p>".$param."</p>";
	//echo "val(".count($params).")-->".implode(',',$params);
	//echo "type(".strlen($prova).")-->".implode("",$type);
	$sql = $db->prepare("....... AND ".implode(" AND ", $fragments));
	array_unshift($params,$prova);
	print_r($params);
	call_user_func_array( array( $sql, 'bind_param' ),$params);
	//$sql->bind_param($prova,$params);
	$sql->execute();

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.