how to only update select fields on a database - php

I have made a users account page where they can update their information.
For my first issue I will be using birthday as an example (it uses three dropdown bars which are saved as the variables $dobday $dobmonth and $dobyear) if a user only inputs one of the variable's - eg $dobdayand then they press 'update' the php will save that to the database, however this is then saving an incomplete date of birth, i have thought about adding a 'requirerd' function on the form, however i want it to be optional if the user only wants to fill out one piece of information. Is there any way I can resolve this by an if statement or another function that I am un aware of?
Secondly, if I enter a number in the phone number field and leave the rest of the fields blank on the form, when the database is updated, the other fields that were not filled in but had something saved in them on the database are wiped.
I am still learning web design so forgive me for my poor code. Thank you very much for your help and time :)
HTML form:
<form class="containerformAccounts" method="post" action="accountpageForm.php" >
<div class="container">
<h1>Edit your account</h1>
<hr>
<h3>Enter your telephone number</h3>
<label for="mobNumber"><b><i>Phone Number:</i></b></label>
<input type="mobNumber" maxlength="11" name="mobNumber" id="mobNumber" placeholder="Enter phone number"> <!--ommiting 'required' as this part is optional-->
</br>
<h3>Enter your address</h3>
<label for ="addressLine"><b><i>Address Line:</i></b></label>
<input type="addressLine" name="addressLine" id="addressLine" placeholder="Enter your address line">
<label for ="townCity"><b><i>Town/City:</i></b></label>
<input type="townCity" name="townCity" id="townCity" placeholder="Enter your town/city">
<label for ="postcode"><b><i>Postcode:</i></b></label>
<input type="postcode" name="postcode" id="postcode" placeholder="Enter your Postcode">
<label for ="country"><b><i>Country:</i></b></label>
<input type="country" name="country" id="country" placeholder="Enter your country">
</br>
<h3>Enter your birthdate</h3>
<label for ="dob-day"><b><i>Birthday:</i></b></label>
<select name="dobday" id="dobday">
<option value="Day">Day</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select name="dobmonth" id="dobmonth">
<option value="Month">Month</option>
<option value="January">January</option>
<option value="Feburary">Feburary</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select>
<select name="dobyear" id="dobyear">
<option value="Year">Year</option>
<option value="1950">1950</option>
<option value="1951">1951</option>
<option value="1952">1952</option>
<option value="1953">1953</option>
<option value="1954">1954</option>
<option value="1955">1955</option>
<option value="1956">1956</option>
<option value="1957">1957</option>
<option value="1958">1958</option>
<option value="1959">1959</option>
<option value="1960">1960</option>
<option value="1961">1961</option>
<option value="1962">1962</option>
<option value="1963">1963</option>
<option value="1964">1964</option>
<option value="1965">1965</option>
<option value="1966">1966</option>
<option value="1967">1967</option>
<option value="1968">1968</option>
<option value="1969">1969</option>
<option value="1970">1970</option>
<option value="1971">1971</option>
<option value="1972">1972</option>
<option value="1973">1973</option>
<option value="1974">1974</option>
<option value="1975">1975</option>
<option value="1976">1976</option>
<option value="1977">1977</option>
<option value="1978">1978</option>
<option value="1979">1979</option>
<option value="1980">1980</option>
<option value="1981">1981</option>
<option value="1982">1982</option>
<option value="1983">1983</option>
<option value="1984">1984</option>
<option value="1985">1985</option>
<option value="1986">1986</option>
<option value="1987">1987</option>
<option value="1988">1988</option>
<option value="1989">1989</option>
<option value="1990">1990</option>
<option value="1991">1991</option>
<option value="1992">1992</option>
<option value="1993">1993</option>
<option value="1994">1994</option>
<option value="1995">1995</option>
<option value="1996">1996</option>
<option value="1997">1997</option>
<option value="1998">1998</option>
<option value="1999">1999</option>
<option value="2000">2000</option>
<option value="2001">2001</option>
<option value="2002">2002</option>
<option value="2003">2003</option>
<option value="2004">2004</option>
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
</select>
</p>
<hr>
<h3>Change your password</h3>
</p><a href='passwordChange.php'>Change your password</a> </br>
</br>
<input type='submit' name='submit' value= 'Update'>
</hr>
</hr>
</div>
PHP:
<?php
session_start();//creating session
$user=$_SESSION['firstName'];
if (isset($_POST['submit'])){
$connectDB = mysqli_connect("localhost","root","") or die("cant connect"); //proving the database connection details and saving it as a variable
mysqli_select_db($connectDB, "registration"); //table name
// BIRTHDAY
$updateDBvalues=array(); //creating array to be used in query
$updateArray=array(); //creating array
$dobday=$_POST['dobday']; //importing variables
$dobmonth=$_POST['dobmonth'];//importing variables
$dobyear=$_POST['dobyear'];//importing variables
//ADDRESS
$addressLine=$_POST['addressLine'];//importing variables
$townCity=$_POST['townCity'];//importing variables
$postcode=$_POST['postcode'];//importing variables
$country=$_POST['country'];//importing variables
//NUMBER
$mobNumber=$_POST['mobNumber'];//importing variables
//NUMBER BELOW
if(!empty($mobNumber))
$updateArray[]="mobNumber='".$mobNumber."'";
//ADDRESS BELOW
if(!empty($addressLine))//if the variables is NOT empty
$updateArray[]="addressLine='".$addressLine."'";//add the variable to the array
if(!empty($townCity))//if the variables is NOT empty
$updateArray[]="townCity='".$townCity."'";//add the variable to the array
if(!empty($postcode))//if the variables is NOT empty
$updateArray[]="postcode='".$postcode."'";//add the variable to the array
if(!empty($country))//if the variables is NOT empty
$updateArray[]="country='".$country."'";//add the variable to the array
//BIRTHDAY BELOW
if(!empty($dobday))//if the variables is NOT empty
$updateArray[]="dobday='".$dobday."'";//add the variable to the array
if(!empty($dobmonth))//if the variables is NOT empty
$updateArray[]="dobmonth='".$dobmonth."'";//add the variable to the array
if(!empty($dobyear))//if the variables is NOT empty
$updateArray[]="dobyear='".$dobyear."'";//add the variable to the array
$updateDBvalues=$updateArray;
$updateDBvalues_imploded=implode(',',$updateDBvalues); // takes the array and makes one string
if(!empty($updateDBvalues)){ //if the array is NOT empty
$query="UPDATE users SET $updateDBvalues_imploded WHERE firstName='$user'";//sql query to save entries into table
$connQuery=mysqli_query($connectDB,$query);//querys database
die("Succesfully updated, return to <a href='accountPage.php'>Accounts page</a>");//successful query, provides link for user to return to account page
}else{
die ("Unable to save new infomation to the database, please try again. <a href='accountPage.php'>Accounts page</a>");//kills program, outputting that the query was unsuccessful, provides link for user to return to account page
}
}
?>

Well, you don't want to nullify your previously save data in fields. For that you can use COALESCE function in MySQL. It returns the first not null value in the parameters.
For example, you can set fields this way:
$updateArray[]="dobyear= coalesce('".$dobyear."', dobyear)"
But what about the situations where you really want to nullify the field. The better approach will be to populate the form with data in the database. Now, you can simply save the complete form with changes by the user.

Related

Day of the Year Program

So I have this code that creates a drop down box to select a month, another drop down box to select the day, then a text field to type in a year. My question is what to do next in php to be able to select a certain month, day, and year to where, when i click "calculate," it will display what day of that year it is?
So for example, if i choose January 4 2015, when i click calculate, i want it to display 4 since it is the 4th day of the calendar year. How do I do that?
<form action="calc.php" method="post">
Month: <select name="month">
<option value="january">January</option>
<option value="february">February</option>
<option value="march">March</option>
<option value="april">April</option>
<option value="may">May</option>
<option value="june">June</option>
<option value="july">july</option>
<option value="august">August</option>
<option value="september">September</option>
<option value="october">October</option>
<option value="november">November</option>
<option value="december">December</option>
</select>
Day: <select name="day">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<input name="entry" type="text" size="10" placeholder="Year">
<input type="submit" value="Calculate">
</form>
You can use date:
echo date("z", strtotime('2015-01-04'));
But it returns:
The day of the year (starting from 0)
So you need to add 1 to the result.
you can try the below code to get the day of the date . here i am using the same page for the post. if you are using another page for posting (i mean action page) use the php inside that file,
HTML
<form action="#" method="post">
Month: <select name="month">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">july</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
Day: <select name="day">
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
<option value="08">8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<input name="year" type="text" size="10" placeholder="Year">
<input type="submit" name="submit" value="Calculate">
</form>
PHP
<?php
if(isset($_POST['submit']))
{
$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
echo date("l", strtotime($date));
}
?>

PHP POST data not coming through with enctype="multipart/form-data"

I'm having trouble getting my form's post data to come through. As this code stands, the file uploads, but I don't have any post data for the other form fields. I noticed that if I get rid of multipart/form-data enctype, it will not upload (obviously) but I DO get the post data to come through for the other fields. Any ideas on why this is?
The page where this code occurs is index.php?page=page1&upload=1
<form enctype="multipart/form-data" action="?page=page1&upload=2" method="post">
Select Location: <select name="location">
<option>Select Location</option>
<option value="N">North</option>
<option value="S">South</option>
<option value="E">East</option>
<option value="W">West</option>
</select><br />
Upload File: <input name="ufile" type="file" id="ufile" size="50" /><br />
<b><u>Sunday</u></b> Date: <select name="month">
<option> - Month - </option>
<option value="01">January</option>
<option value="02">Febuary</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="day">
<option> - Day - </option>
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
<option value="08">8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select name="year">
<?php
$optionyear = date("Y",time());
$currentyear = $optionyear;
while($optionyear != 1990) {
echo "<option value=\"".$optionyear."\"";
if($optionyear == $currentyear) {
echo " selected";
}
echo ">".$optionyear."</option>";
$optionyear--;
}
?>
</select><br />
<input type="submit" name="Submit" value="Upload" /><br />
</form>
Thanks!
U can get your upload data with $_FILES[] and other data with $_POST[]
Try
echo "<pre>";
print_r($_POST);
print_r($_FILES['ufile']);
echo "</pre>";
By the way where is close tag for <form> element?

How to carry form data from a select field to another form (having the same elements) in a select field?

Okay, I know that's a bit too premature but I didn't get any satisfactory answers wherever I tried to search. What I want to do is basically, collect form data from the users, validate(PHP) them, assuming they have JavaScript disabled I want to show errors in the next page with PHP. And I also want to show them the same form that they worked on earlier. The difference is that there would be error messages and the form fields would be pre-filled with the data they entered. I have succeeded in the text fields and radio fields. But it's proving difficult for me to show them the select field input. . Help is very much appreciated and thanks in advance.
this is 1st form's select fields:
<select name="month" id="month">
<option value="-1"> Month: </option>
<option value="1">Jan</option>
<option value="2">Feb</option>
<option value="3">Mar</option>
<option value="4">Apr</option>
<option value="5">May</option>
<option value="6">Jun</option>
<option value="7">Jul</option>
<option value="8">Aug</option>
<option value="9">Sep</option>
<option value="10">Oct</option>
<option value="11">Nov</option>
<option value="12">Dec</option>
</select>
</select>
<select name="day" id="day">
<option value="-1">Day:</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select name="year" id="year"><option value="-1" selected="selected">Year</option><option value="2000">2000</option><option value="1999">1999</option><option value="1998">1998</option><option value="1997">1997</option><option value="1996">1996</option><option value="1995">1995</option><option value="1994">1994</option><option value="1993">1993</option><option value="1992">1992</option><option value="1991">1991</option><option value="1990">1990</option><option value="1989">1989</option><option value="1988">1988</option>
</select>
and the php to get the variables:
<?php //setting checking
$month=$_POST['month'];
$day=$_POST['day'];
$year=$_POST['year'];
?>
the second select fields are as same as the first one
If you want to show selected value in selectbox than:
<select name="day" id="day">
<option value="1" <?php if($_POST['day']==1){ echo 'selected="selected"'} ?>></option>
.
.
.
//rest will be same
</select>
Same thing you can do for your all select boxes.

Data type required in a mysql for a date containing day-month-year

Hi guys I'm using wamp server and I have a database with a date of birth field. I would simply like to know what data type would be suitable for the way date of birth is specified on my website (January 01 1996).
I would like to get a sample mysql query using the DATE_FORMAT() function. Most of the posts I've seen use SELECT and SELECT*. But I believe this should be replaced with UPDATE. As in UPDATE users SET dob = DATE_FORMAT(dob, '%m/%d/%Y')); .
Please find my code for how the date of birth is specified below:
<label id= "dob" for="dob">Date of birth:</label>
<!-- Month dropdown -->
<select name="dob" id="month" onchange="" size="1">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<!-- Day dropdown -->
<select name="dob" id="day" onchange="" size="1">
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select id="birthyear" name="dob">
<option value="1996">1996</option>
<option value="1995">1995</option>
<option value="1994">1994</option>
<option value="1993">1993</option>
<option value="1992">1992</option>
<option value="1991">1991</option>
<option value="1990">1990</option>
<option value="1989">1989</option>
<option value="1988">1988</option>
<option value="1987">1987</option>
<option value="1986">1986</option>
<option value="1985">1985</option>
<option value="1984">1984</option>
<option value="1983">1983</option>
<option value="1982">1982</option>
<option value="1981">1981</option>
<option value="1980">1980</option>
<option value="1979">1979</option>
<option value="1978">1978</option>
<option value="1977">1977</option>
<option value="1976">1976</option>
<option value="1975">1975</option>
<option value="1974">1974</option>
<option value="1973">1973</option>
<option value="1972">1972</option>
<option value="1971">1971</option>
<option value="1970">1970</option>
<option value="1969">1969</option>
<option value="1968">1968</option>
<option value="1967">1967</option>
<option value="1966">1966</option>
<option value="1965">1965</option>
<option value="1964">1964</option>
<option value="1963">1963</option>
<option value="1962">1962</option>
<option value="1961">1961</option>
<option value="1960">1960</option>
<option value="1959">1959</option>
<option value="1958">1958</option>
<option value="1957">1957</option>
<option value="1956">1956</option>
<option value="1955">1955</option>
<option value="1954">1954</option>
<option value="1953">1953</option>
<option value="1952">1952</option>
<option value="1951">1951</option>
<option value="1950">1950</option>
<option value="1949">1949</option>
<option value="1948">1948</option>
<option value="1947">1947</option>
<option value="1946">1946</option>
<option value="1945">1945</option>
<option value="1944">1944</option>
<option value="1943">1943</option>
<option value="1942">1942</option>
<option value="1941">1941</option>
<option value="1940">1940</option>
<option value="1939">1939</option>
<option value="1938">1938</option>
<option value="1937">1937</option>
<option value="1936">1936</option>
<option value="1935">1935</option>
<option value="1934">1934</option>
<option value="1933">1933</option>
<option value="1932">1932</option>
<option value="1931">1931</option>
<option value="1930">1930</option>
<option value="1929">1929</option>
<option value="1928">1928</option>
<option value="1927">1927</option>
<option value="1926">1926</option>
<option value="1925">1925</option>
<option value="1924">1924</option>
<option value="1923">1923</option>
<option value="1922">1922</option>
<option value="1921">1921</option>
<option value="1920">1920</option>
</select>
</p>
When saving date in the database, use the correct datatype DATE or DATETIME. Don't use VARCHAR
Pros:
easy to manipulate
requires no casting when manipulating data
index will be used (if a key was defined)
Cons
can't think of something..
If the reason why you want to save date in this format January 01 1996 is because it is more readable than 1996-01-01, then don't. This can be achieve using DATE_FORMAT() during the projection of the data.
$query = "INSERT INTO users (username, date_of_birth) ";
$query .= "VALUES ('John Doe', 'DATE: Manual Date', '2008-7-04')";
The manual date acts somewhat like most StringToTime functions in most scripting languages.
Another way to store time, and is actually a little bit more efficient, is to use the scripting language (like PHP) to format the time into microtome and store it in the database as an INT(11). So when retrieving the microtime back from the database you can just display it any way you like and is even faster to just do calculations with it :).

jQuery dynamiclly added from field wont submit

I have a bit of jQuery that allows people to add form fields dynamically based on the number of children they have.
var childCount = $('.newchildsub').length + 1;
$('.newchildsub:last').after($('.newchildsub:first').clone().removeAttr('id').attr('id', 'child-' + childCount).insertAfter('.newchildsub:last'));
$('#child-' + childCount).find('#childId').remove();
$('#child-' + childCount).find('#gender').attr('name', 'children[child-' + childCount + '][gender]').attr('value', '');
$('#child-' + childCount).find('#month').attr('name', 'children[child-' + childCount + '][month]').attr('value', '');
$('#child-' + childCount).find('#year').attr('name', 'children[child-' + childCount + '][year]').attr('value', '');
The code works prefect to add the fields and increase the name but when I click submit and print_r($_POST);, the dynamically created field is not there.
Below is an example of my html including the dynamically generated field (child-3), which is based of the first one as you can see in the jQuery.
<div id="child-1" class="newchildsub">
<h4>Gender: </h4><input type="hidden" id="childId" name="children[child-1][id]" value="394820">
<select name="children[child-1][gender]" id="gender">
<option value="">--</option>
<option value="male" selected>Male</option>
<option value="female">Female</option>
</select>
<h4>Birthday: </h4>
<select name="children[child-1][month]" id="month">
<option value="">Month</option>
<option value="01">January</option>
<option value="02" selected>February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="children[child-1][year]" id="year">
<option value="">Year</option>
<option value="2012" selected>2012</option>
<option value="2011">2011</option>
<option value="2010">2010</option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
<option value="2000">2000</option>
</select><br><br>
</div>
<div id="child-2" class="newchildsub">
<h4>Gender: </h4>
<input type="hidden" id="childId" name="children[child-2][id]" value="394821">
<select name="children[child-2][gender]" id="gender">
<option value="">--</option>
<option value="male">Male</option>
<option value="female" selected>Female</option>
</select>
<h4>Birthday: </h4>
<select name="children[child-2][month]" id="month">
<option value="">Month</option>
<option value="01" selected>January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="children[child-2][year]" id="year">
<option value="">Year</option>
<option value="2012">2012</option>
<option value="2011" selected>2011</option>
<option value="2010">2010</option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
<option value="2000">2000</option>
</select><br><br>
</div>
<div id="child-3" class="newchildsub">
<h4>Gender: </h4>
<select id="gender" name="children[child-3][gender]">
<option value="">--</option>
<option selected="" value="male">Male</option>
<option value="female">Female</option>
</select>
<h4>Birthday: </h4>
<select id="month" name="children[child-3][month]">
<option value="">Month</option>
<option value="01">January</option>
<option selected="" value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select id="year" name="children[child-3][year]">
<option value="">Year</option>
<option selected="" value="2012">2012</option>
<option value="2011">2011</option>
<option value="2010">2010</option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
<option value="2000">2000</option>
</select><br><br>
</div>
According to your code you are changing the id, but not the name attribute for the cloned fields.
The name attribute has to be unique and that's why you don't see the dynamically added fields.
Add your name attribute into your jQuery code.
You have to manage name of your input element.
You can give them the name uniquely or give the name as un-indexed array like children[gender][]. Php will parse them and treat as array by creating index automatically for that. This link may help

Categories