dimanche 19 avril 2020

Checkbox Selection & Updating

I have a user checkbox selection in a form. They select all the options that they want. Using php, html, and mysql.

Below is the code to get it into the database after the user made their checkbox selections.

$test=$_POST['userselections']; $test2=serialize($test);

mysqli_query($connection, "INSERT INTO selections VALUES('$test2')");

The result is then stored in the database. The below is an example of what it looks like in the database.

a:2:{i:0;s:5:"Test1";i:1;s:5:"Test2";}

I want to be able to allow the user to make additional selections updating the stored data in the database.

I have tried to use serialize and unserialize and nothing works.

I have also tried using arrays and serializing to replicate checkbox. Attempting to get the data to look like the checkbox "a:2:{i:0;s:5:"Test1";i:1;s:5:"Test2";}".

I need to have an array stored in the database and be able to call it out and add to it when needed. I need an array so I can use the count feature and see how many options have been selected. I want to run a check where it checks all entry's in the array that the new selection is not currently in the array and if not then it adds it. Not sure if i am using the right features for this or if i am just messing up the code.

Any suggestions how to properly have an array where you can check and add new entries?




Aucun commentaire:

Enregistrer un commentaire