PHP : insert multiple check boxes values into one MySQL column

前端 未结 5 1918
余生分开走
余生分开走 2020-12-14 13:30

I want to write a simple PHP function to insert values of 10 and 20 check boxes. Now, the issue is: should I insert all values in a single column of MySQL table or should I

5条回答
  •  我在风中等你
    2020-12-14 13:56

    I put the game name into the brackets and changed their values to true:

    Games You Like:








    After submission this will result in an array like this:

    $_POST["games"] = Array ( [Tennis] => true [Cricket] => true [Table] => true ) 
    // all other values false
    

    You can easily store and later manipulate this array if you store it as an JSON string in your database. For that you need a single varchar or text column.

    json_encode($_POST["games"])
    // {"Tennis":"true","Cricket":"true","Table":"true"}
    

提交回复
热议问题