I recieved the following warning:
Warning: implode() [function.implode]: Invalid arguments passed.
What caused this and how can I fix it?
$title = $_POST[photo_name_id];
if($title)
{
foreach($title as $titled)
{
$judul[] = $titled;
}
}
$titleds = "('".implode("'), ('",$judul)."')";
and this is my form:
<tr>
<td>
<?
$pm1= mysql_query("SELECT photo_name FROM photo_name WHERE photo_name_id = 1");
$dpm1 = mysql_fetch_array ($pm1);echo"$dpm1[0]"
?>
<input type='hidden' name='photo_name_id[]' value='<?echo"$dpm1[0]"?>'> :
</td>
</tr>
<tr>
<td>
<?
$pm1= mysql_query("SELECT photo_name FROM photo_name WHERE photo_name_id = 2");
$dpm1 = mysql_fetch_array ($pm1);echo"$dpm1[0]"
?>
<input type='hidden' name='photo_name_id[]' value='<?echo"$dpm1[0]"?>'> :
</td>
</tr>
What happens if
$titleevaluates to false? Then your if statement won’t execute and the array won’t be created.implode()will complain with a warning because an unset variable is passed in. It wanted an array.You should either initialize
$judulto an empty array or place the implode in your if.Also, quote your array keys. It’s bad practice not to, because initially PHP assumes they are constants.
Or this (more preferable, because
$titledswill always be set):However this all prompts the question. Why are you copying
$titleinto a new array. Why not just do: