Hi there i have a form (with specific id) that has checkboxes in it and when the checkbox is clicked, more questions (basicly a text field) will pop up. However some checkboxes have the same questions inside. Then I am saving the data to a mysql database. And i am displaying it afterwards. And the Question is: How to create some sort of switch statement or some algorithm that it would post in the current id and only to desired textfield.
Fo illustration:
0-100kg (Checkbox1)
- Which material? (textfield with name=material)
- Circle radius? (textfield with name=radius)
100-500kg (Checkbox2)
- Which material? (textfield with name=material)
- Circle radius? (textfield with name=radius)
500-1000kg (Checkbox3)
- Which material? (textfield with name=material)
- Circle radius? (textfield with name=radius)
- Roots? (textfield with name=roots)
Code:
Form:
<label class="collapse" for="100to500"><b>100 - 500kg</b></label>
<input id="100to500" type="checkbox" name="100to500">
<div><br>
Which material? <input type="text" name="material"/><br>
Circle radius? <input type="text" name="radius"/><br></div>
<label class="collapse" for="500to1000"><b>500 - 1000kg</b></label>
<input id="500to1000" type="checkbox" name="500to1000">
<div><br>
Which material? <input type="text" name="material"/><br>
Circle radius? <input type="text" name="radius"/><br>
Roots? <input type="text" name="roots"/><br></div>
PHP:
storing variables:
$material=mysql_real_escape_string($_POST['material']);
$radius=mysql_real_escape_string($_POST['radius']);
$roots=mysql_real_escape_string($_POST['roots']);
$100to500 = isset($_POST['100to500']) ? $_POST['100to500'] : '0';
$500to1000= isset($_POST['500to1000']) ? $_POST['500to1000'] : '0';
I am trying to accopmlish that it would somehow save all the data into same id (database row) and save only the clicked on / filled data. I know it is a silly explanation but i am using PHP for 2 weeks only so im a complete noob :)
Thank you.