Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inserting checkboxes into table?

Status
Not open for further replies.

tshey

Technical User
Dec 28, 2005
78
AU
I know you guys have proberly had lots of this question, however I will ask again. I have an array of checkboxes and want the user to select the desired checkboxes that relate. this means multiple values will go into one colum. what is the easiest way of doing this?
 
Wasn't first quite sure, were you talking about database tables and columns or HTML. But I'm quessing database.

What is an array of checkboxes (this made me think of HTML...)? Are you talking about an array you receive, when multiple values are selected? Like

$array = $_POST['choice'];

You'll need to insert them into database separetly in a loop, foreach I would recommend.

No multiple values in to column. No multiple values of ceratain instance into same table, I might add.
 
I have made an array input type="checkbox" name="catagory[]" value="reception". how can I get multiple checkbox values into one column in a table of a database. What about implode?
 
You can convert your PHP arrays into a format that can be stored in a database by using the serialize function.
Code:
$category = $_POST['category']

$db_category = serialize($category);

When you fetch it back from the database use unserialize() and it will be a usable PHP array again:

Code:
unserialize($db_category);

 
Where do I put this code? this is the nearest I can find
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO customers (category) VALUES (%s)",
GetSQLValueString ($_POST['category'], "text"));
$db_category = serialize($category);
But it doesn't work array just appears?
sorry I am a bit new at php
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top