Page 1 of 1

Problem with checkboxes and implode

Posted: Wed Jun 23, 2004 11:48 am
by jamesmiddz
Hi, I'm stuck again,

I have a form that submits information to my MySQL database>table. Some of the information is collect via Checkboxes. I want the contents of any chosen checkbox to be applied to only one field in my table. I have tried so many methods, I just can't get it working. I think it all come down to Implode() but I'm stuck on its implementation.

Here's what I've done so far; form.php

Code: Select all

<form enctype="multipart/form-data" action="insert.php" method="post">
<input type="checkbox" name="facilitiesї]" value="Clubhouse">
Clubhouse<br>
<input type="checkbox" name="facilitiesї]" value="Holiday caravan hire">
Holiday caravan hire<br>
<input type="checkbox" name="facilitiesї]" value="Games room">
Games room<br>
<input class="formblockgrey" type="submit" name="submit" value="Add Details">
</form>
insert.php

Code: Select all

<?php 
include("connector.php"); //usual mysql connect stuff

$query = "INSERT INTO hotel (facilities) 
VALUES('".$_POST['facilities']."')"; 

$result = mysql_query($query); 
 
?>
I have trimmed out all other fields just for the sake of the coding here. I anyone could help me on this, It would make me a happy man

Posted: Wed Jun 23, 2004 11:52 am
by markl999
Well, $_POST['facilities'] will be an array of values. So you need to join them in some way, eg:

Code: Select all

if(!empty($_POST['facilities'])){
    $query = "INSERT INTO hotel (facilities) VALUES('".join(',', $_POST['facilities'])."')";
    $result = mysql_query($query) or die(mysql_error());
}
that will put them comma separated into the db field.