Jump to content

inserting items into db from checkbox


perezf

Recommended Posts

Hi guys i have these checkboxes that im trying to insert into a db separated by the pipe symbol,

How can i do it?

 

these are my checkboxes

 

<input type="checkbox" name="interestlifestyles[]" value="1">
<input type="checkbox" name="interestlifestyles[]" value="2">
<input type="checkbox" name="interestlifestyles[]" value="3">
<input type="checkbox" name="interestlifestyles[]" value="4">
<input type="checkbox" name="interestlifestyles[]" value="5">

Link to comment
https://forums.phpfreaks.com/topic/106997-inserting-items-into-db-from-checkbox/
Share on other sites

you want all selected values separated by a pipe symbol, then inserted into a single field, correct? if so, this works for me:

 

<?php
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$in_value = implode('|',$_POST['interestlifestyles']);
$sql = "INSERT INTO some_table (some_field) VALUES ('$in_value')";
echo $sql;
}
?>
<FORM METHOD='POST'>
<input type="checkbox" name="interestlifestyles[]" value="1">
<input type="checkbox" name="interestlifestyles[]" value="2">
<input type="checkbox" name="interestlifestyles[]" value="3">
<input type="checkbox" name="interestlifestyles[]" value="4">
<input type="checkbox" name="interestlifestyles[]" value="5">
<INPUT TYPE='submit'>
</FORM>

 

output:

 

INSERT INTO some_table (some_field) VALUES ('1|2|4')

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.