mysql - how to insert record to database with checkbox other option in php? -


i have form :

enter image description here

i confused how put database. have code :

echo "<form action='insert.php'>";   $data = array("rice","fish","pizza","other");   for($i=1; $i<5; $i++){      echo "<input type='text' name='food[]' value='$i' class='food'><label>$data[$i]</label>";   }   echo "<input type='submit' value='ok'>"; echo "</form>"; <script>     $(".food").change(function () {         if (this.checked && this.value=='4') {             $(this).next("label").after("<p id='other-text'><input placeholder='please enter food' type='text' name='otherfood[]' /></p>")         } else {             $("#other-text").remove();         }     }); </script> 

database:

order id   id_food  other ---------------------- 1       4      soup 

can me how put database tabel order ?

order id   id_food  other ---------------------- 1       4      soup 

i don't think it's idea store data that. if need store id_food = 4 (which refers 'other') along 'soup', suggest customizing food lookup table follows:

food id   name  is_other ---------------------- 1    pizza 0 5    soup  1 

and modifing order table follows

order id   id_food  other_id ---------------------- 1       4      5 

this way can preserve data integrity , keep table size optimal checking if text provided in other textbox exists in food table , if select id_food , insert food_id in order table.

and can still filter checkboxes following condition if not wish manually entered data visible on form

select id,name food is_other = 0 

or

since have data soup in food table, can list along other food options checkbox.

this 1 option, there different approaches i'm sure provided other users.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -