-3

I want to get data from CF7 checkboxes and then save them to the same column in the MySQL database.

For example form is like that:

First and Last name: First Last

What do you like:

X cars, X bikes, X planes

Where did you hear about us? (Dropdown) FB IG Google

  • X is checked box.

Script I use for saving values excluding the multiple checkbox:

$firstLastName = $data["first-last"];
$marketing_source = $data["marketing_source"];



$mydb->insert(
   'TableName',
    array(
        'firstLastName' => $firstLastName,
        'marketing_source' => $marketing_source[0],
    ),
    array(
          '%s','%s',
    )
);

So I want to add a line that will also save multiple selections when user selects more fields in checkbox.

blazk
  • 5
  • 2
  • So `$data["marketing_source"]` contains the checked checkboxes here? Well just `implode` that into a single string value then. – CBroe Oct 20 '21 at 10:36
  • 1
    This is a really bad idea. You'll run into all sorts of difficulties if you come to try to select or sort based on the data in that column. If you're never going to do that, maybe it's OK. – droopsnoot Oct 20 '21 at 10:46
  • you can save use implode(", " , $marketing_source); – Majid Ahmadi Oct 20 '21 at 11:12

1 Answers1

0
'like' => $like[0].", ".$like[1].", ".$like[2].", ".$like[3],

this code when you want to put values to MySQL db.

blazk
  • 5
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 20 '21 at 10:52
  • You might benefit from reading this [Is storing a delimited list in a database column really that bad?](https://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad) – RiggsFolly Oct 20 '21 at 10:53