Page 1 of 1

problem with implode()

Posted: Sun Feb 17, 2008 5:19 pm
by drace
Hi there,

i've got a very simple database that is displayed in a html table. each entry in the table has a unique id which is the primary key, each row in the table has a checkbox.

This is part of the code that loads data into the table (php while loop, $ID is ID of entry)

Code: Select all

echo "<tr> <td> <input type=checkbox name='check[]' value='$ID'> </td>";
Once the user has made his selection the editform is called up in a separate window using this javascript function:

Code: Select all

function OpenWindow()
{
  window.open(editform.php,'mywindow','width=400,height=300');
  header("Location: http://localhost/");
}
editform.php then proceeds to get the array with the value of the checkboxes like this:

Code: Select all

$check = $_REQUEST['check'];
$idlist = implode(",", $check);
which is supposed to give me a variable containing the id of the entry the user has selected via the checkbox.

This does not work. this is the error message i am getting:

Warning: implode() [function.implode]: Invalid arguments passed in C:\xampp\htdocs\editform.php on line 33

i am a bit stuck, is there an alternate way to pass the id to the editform, or a way to get the implode function working in this context? any help would be greatly appreciated.

Re: problem with implode()

Posted: Sun Feb 17, 2008 5:33 pm
by Benjamin
What is the contents of $check?

Re: problem with implode()

Posted: Sun Feb 17, 2008 5:42 pm
by drace
hi,

Code: Select all

echo("check: $check");
gives me this:

check:

thus i would say $check is empty

Re: problem with implode()

Posted: Sun Feb 17, 2008 5:51 pm
by Benjamin
Can't really implode an empty string heh.

Re: problem with implode()

Posted: Sun Feb 17, 2008 6:10 pm
by Luke
Implode expects an array (second arg) and returns a string. If it doesn't get an array, it throws an error. Try something like:

Code: Select all

$check = isset($_POST['check']) ? $_POST['check'] : array();
$idlist = implode(",", $check);
Checkboxes work a little strange... if you don't check it, it isn't included in the $_POST array at all. So you have to check that the value exists before attempting to use it.

Re: problem with implode()

Posted: Mon Feb 18, 2008 3:33 am
by drace
thats great, ill give that a try. thanks for your help