cant add array number in dynamic cakephp form - php

I am trying to make a dynamic form in CakePHP, but it seems not to work.
What can I do to make it work; I can't get data[AppliedCourses][0][institution], can't get data[AppliedCourses][1][institution], data[AppliedCourses][2][institution], etc.
<table id="mytable2" style="border: 0px;">
<tbody>
<tr id="InstitutionApplied0">
<td>
<button type="button" title="Click Here to remove Institution Applied" style="display: none;">-</button>
<div class="input text">
<label for="AppliedCourses0Institution">Institution Name</label>
<input name="data[AppliedCourses][0][institution]" type="text" id="AppliedCourses0Institution" />
</div>
<div class="input select">
<label for="AppliedCourses0CourseId">Course Of Interest</label>
<select name="data[AppliedCourses][0][course_id]" id="AppliedCourses0CourseId">
<option value="1">Applied Sciences</option>
<option value="2">Architecture & Built Enviroment</option>
<option value="3">Art & Design</option>
<option value="4">Business / Commerce</option>
<option value="5">Computing & IT</option>
<option value="6">Communication & Media Studies</option>
<option value="7">Education & Language</option>
<option value="8">Engineering</option>
<option value="9">Environmental Science</option>
<option value="10">Health Sciences</option>
<option value="11">Hospitality & Tourism</option>
<option value="12">Humanities & Social Sciences</option>
<option value="13">Law & Legal Studies</option>
<option value="14">Music</option>
<option value="15">Others</option>
</select>
</div>
<div class="input text">
<label for="AppliedCourse0Major">Major Field Of Course</label>
<input name="data[AppliedCourse][0][major]" maxlength="255" type="text" id="AppliedCourse0Major" />
</div>
<div class="input date">
<label for="AppliedCourses0IntakeMonth">Intake</label>
<select name="data[AppliedCourses][0][intake][month]" id="AppliedCourses0IntakeMonth">
<option value="01">January</option>
<option value="02">February</option>
<option value="03" selected="selected">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="data[AppliedCourses][0][intake][year]" id="AppliedCourses0IntakeYear">
<option value="2035">2035</option>
<option value="2034">2034</option>
<option value="2033">2033</option>
<option value="2032">2032</option>
<option value="2031">2031</option>
<option value="2030">2030</option>
<option value="2029">2029</option>
<option value="2028">2028</option>
<option value="2027">2027</option>
<option value="2026">2026</option>
<option value="2025">2025</option>
<option value="2024">2024</option>
<option value="2023">2023</option>
<option value="2022">2022</option>
<option value="2021">2021</option>
<option value="2020">2020</option>
<option value="2019">2019</option>
<option value="2018">2018</option>
<option value="2017">2017</option>
<option value="2016">2016</option>
<option value="2015" selected="selected">2015</option>
<option value="2014">2014</option>
<option value="2013">2013</option>
<option 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>
<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>
</select>
</div>
<div class="input date">
<label for="AppliedCourses0SubmissionDateDay">Submission Date</label>
<select name="data[AppliedCourses][0][submission_date][day]" id="AppliedCourses0SubmissionDateDay">
<option value="01">1</option>
<option value="02" selected="selected">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="data[AppliedCourses][0][submission_date][month]" id="AppliedCourses0SubmissionDateMonth">
<option value="01">January</option>
<option value="02">February</option>
<option value="03" selected="selected">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="data[AppliedCourses][0][submission_date][year]" id="AppliedCourses0SubmissionDateYear">
<option value="2035">2035</option>
<option value="2034">2034</option>
<option value="2033">2033</option>
<option value="2032">2032</option>
<option value="2031">2031</option>
<option value="2030">2030</option>
<option value="2029">2029</option>
<option value="2028">2028</option>
<option value="2027">2027</option>
<option value="2026">2026</option>
<option value="2025">2025</option>
<option value="2024">2024</option>
<option value="2023">2023</option>
<option value="2022">2022</option>
<option value="2021">2021</option>
<option value="2020">2020</option>
<option value="2019">2019</option>
<option value="2018">2018</option>
<option value="2017">2017</option>
<option value="2016">2016</option>
<option value="2015" selected="selected">2015</option>
<option value="2014">2014</option>
<option value="2013">2013</option>
<option 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>
<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>
</select>
</div>
</td>
</tr>
<tr>
<td>
<button type="button" title="Click Here to add another Institution" onclick="addInstitution()">+</button>
</td>
</tr>
</tbody>
and the JS
<script>
var lastRowInstitutionApplied = 0;
function addInstitution() {
lastRowInstitutionApplied++;
$("#mytable2 tbody>tr:#InstitutionApplied0").clone(true).attr('id', 'InstitutionApplied' + lastRowInstitutionApplied).removeAttr('style').insertBefore("#mytable2 tbody>tr:#trAdd3");
$("#InstitutionApplied" + lastRowInstitutionApplied + " button").attr('onclick', 'removeInstitutionApplied(' + lastRowInstitutionApplied + ')').attr('style', 'display:block;');
$("#InstitutionApplied" + lastRowInstitutionApplied + " input:first").attr('name', 'data[appliedCourse][' + lastRowInstitutionApplied + '][institution]').attr('id', 'AppliedCourseInstitution' + lastRowInstitutionApplied);
$("#InstitutionApplied0" + lastRowInstitutionApplied + " select").attr('name', 'data[appliedCourse][' + lastRowInstitutionApplied + '][course_id]').attr('id', 'AppliedCourseCourseId' + lastRowInstitutionApplied);
$("#InstitutionApplied0" + lastRowInstitutionApplied + " input:eq(2)").attr('name', 'data[appliedCourse][' + lastRowInstitutionApplied + '][major]').attr('id', 'AppliedCourseCourseMajor' + lastRowInstitutionApplied);
$("#InstitutionApplied" + lastRowInstitutionApplied + " select(1)").attr('name', 'data[AppliedCourse][' + lastRowInstitutionApplied + '][intake]').attr('id', 'AppliedCourseIntake' + lastRowInstitutionApplied);
$("#InstitutionApplied" + lastRowInstitutionApplied + " select(2)").attr('name', 'data[AppliedCourse][' + lastRowInstitutionApplied + '][submission_date]').attr('id', 'AppliedCourseDate' + lastRowInstitutionApplied);
}
function removeInstitutionApplied(x) {
$("#InstitutionApplied" + x).remove();
lastRowInstitutionApplied--;
}
</script>

Related

Hotel Reservation Date Selector

I'm currently working on a hotel website which needs a section to select a booking based on the user's arrival and departure date selection. I am having an issue with getting the PHP to run and redirect to a URL with the drop down selector's values incorporated in.
So far for HTML I have:
<span name="checkIn">
<tr>
<td>
<span class="formtext">
<strong>Check-In:</strong>
</span>
</td>
<td>
<span class="custom-dropdown custom-dropdown--white custom-dropdown--small">
<select name="checkInMonth" class="custom-dropdown__select custom-dropdown__select--white">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05" selected="selected">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>
</span>
</td>
<td>
<span class="custom-dropdown custom-dropdown--white custom-dropdown--small">
<select name="checkInDate" class="custom-dropdown__select custom-dropdown__select--white">
<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" selected="selected">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>
</span>
</td>
<td>
<span class="custom-dropdown custom-dropdown--white custom-dropdown--small">
<select name="checkInYear" class="custom-dropdown__select custom-dropdown__select--white">
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2016">2017</option>
<option value="2016">2018</option>
<option value="2016">2019</option>
<option value="2016">2020</option>
<option value="2016">2021</option>
<option value="2016">2022</option>
<option value="2016">2023</option>
<option value="2016">2024</option>
<option value="2016">2025</option>
<option value="2016">2026</option>
<option value="2016">2027</option>
<option value="2016">2028</option>
<option value="2016">2029</option>
<option value="2016">2030</option>
<option value="2016">2031</option>
<option value="2016">2032</option>
<option value="2016">2033</option>
<option value="2016">2034</option>
<option value="2016">2035</option>
</select>
</span>
</td>
</tr>
</span>
<tr>
<td>
Book Now
</td>
</tr>
and for PHP:
<?php
$checkInMonth = $_POST['checkInMonth'];
$checkInDate = $_POST['checkInDate'];
$checkInYear = $_POST['checkInYear'];
$checkOutMonth = $_POST['checkOutMonth'];
$checkOutDate = $_POST['checkOutDate'];
$checkOutYear = $_POST['checkOutYear'];
header("Location: http://book.[REDACTED].com/[REDACTED]/selectRoom.do?propertyCode=XXXXX&arrivalDay=$checkInDate&arrivalMonthYear=$checkInYear$checkInMonth&departureDay=$checkOutDate&departureMonthYear=$checkOutYear$checkOutMonth");
?>
What am I doing wrong?
Based on the code you've pasted, it seems that you aren't using a form. Therefore, when you click on the "Book now" link no data are passed to your PHP page. Consider wrapping those elements inside a form, setting the action to bookengine.php, and having a proper submit button.

I can't echo certain variables?

I am trying to validate my form using php. The thing is I have 2 radio button's and 3 select.When I echo out my code below nothing happens, no error is shown but the variables do not echo.
if I change my code and exclude"$sex,$month,$day & $year" it echos. I am wondering if I should use jquery to validate the select and radio fields? or is there a better structure in php to do this?
My html is this:
<form id="fleft" action="signup.php" method="POST">
<input type="text" id="box1" name="username" maxlength="30"/><br><br>
<input type="text" id="box2" name="FirstName" maxlength="30"/>
<input type="text" id="box3" name="LastName" maxlength="30"/><br><br>
<input type="text" id="box4" name="Emailadd" maxlength="50"/>
<input type="text" id="box5" name="reEmailadd" maxlength="50"/><br><br>
<input type="password" id="box6" name="Password" maxlength="30"/>
<input type="password" id="box7" name="rePassword" maxlength="30"/><br><br>
<input type="radio" name="sex" value="Male"><label id="male" for="Male"> Male </label>
<input type="radio" name="sex" value="Female"><label id="female" for="female"> Female<br><br>
<label id="d_o_b" for="Date Of Birth">Date Of Birth:</label><br>
<select name="Month">
<option value="Month">Month</option>
<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>
<select name="Day">
<option value="Day">Day</option>
<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 name="Year">
<option value="Year">Year</option>
<option 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>
<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>
<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>
and my php is this:
if (isset($_POST['username']) && isset($_POST['First Name']) && isset($_POST['Last Name']) && isset($_POST['Emailadd']) && isset($_POST['reEmailadd']) && isset($_POST['Password']) && isset($_POST['rePassword']) && isset($_POST['sex']) && isset($_POST['Month']) && isset($_POST['Day']) && isset($_POST['Year'])){
$username = $_POST['username'];
$firstname = $_POST['First Name'];
$lastname = $_POST['Last Name'];
$emailaddr = $_POST['Emailadd'];
$reemailadd = $_POST['reEmailadd'];
$pwd = $_POST['Password'];
$repwd = $_POST['rePassword'];
$sex = $_POST['sex'];
$month = $_POST['Month'];
$day = $_POST['Day'];
$year = $_POST['Year'];
if(!empty($username) && !empty($firstname) && !empty($lastname) && !empty($emailaddr) && !empty($reemailadd) && !empty($pwd) && !empty($repwd) && !empty($sex) && !empty($month) && !empty($day) && !empty($year)){
echo 'ok';
}else {
echo 'incorrect';
Remove Extra space here
$firstname = $_POST['First Name'];
^
$lastname = $_POST['Last Name'];
^
$firstname = $_POST['FirstName'];
$lastname = $_POST['LastName'];
Get array of all $_POST variables
echo '<pre>',print_r($_POST,true),'</pre>';
Add ini_set("display_errors", "1"); to the very top of your PHP script in order to see if you have any undefined variable notices. Because PHP doesn't require variable initialisation, you can call variables that are empty/null without a fatal error.
First of all the mistake I made was in my html:
<select value="Year">
<option value="Year">Year</option>
<option 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>
<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>
<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>
instead it should be:
<select name="Year">
<option value="Year">Year</option>
<option 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>
<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>
<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>

Error posting form data to same page

I have some info that is listed out. One of those fields is submit_date which has the date an application was submitted. On top of this list, I wanted to make a form where with drop down menus we could choose an initial date and a final date and then the list would only show applications submitted between that time range. I got the sql to work and made the form but for some reason whenever I click submit the entire list disappears.
<form name="yearRange" action="index.php" method="post">
Year1:
<select name="year1">
<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>
</select>
Month1:
<select name="month1">
<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>
Day1:
<select name="day1">
<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>
Year2:
<select name="year2">
<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>
</select>
Month2:
<select name="month2">
<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>
Day2:
<select name="day2">
<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 type="submit" name="submit" value="Submit" />
</form>
<?php
if ($DBConn->numRows() > 0) { ?>
<div align="center">
<table border="1" align="center">
<tr>
<td> </td>
<td> </td>
<td><strong>Name</strong></td>
<td><strong>Submit Date</strong></td>
</tr> <?php
$date1="";
$date2="";
if(isset($_POST['year1']) && isset($_POST['year2']) && isset($_POST['month1']) && isset($_POST['month2']) && isset($_POST['day1']) && isset($_POST['day2']))
{
$date1 = $_POST['year1']."-".$_POST['month1']."-".$_POST['day1'];
$date2 = $_POST['year2']."-".$_POST['month2']."-".$_POST['day2'];
}
else{
echo "error";
}
$query = "select * from table1 where submit_date > '$date1' AND submit_date < '$date2'";
$sortQuery = mysql_query($query);
while ($row1=mysql_fetch_assoc($sortQuery))
{
?>
<tr>
<td valign="top"><?php echo $row1['lname'] . ", " . $row1['fname'] . " " . $row1['mname']; ?></td>
<td valign="top"><?php echo date('Y-m-d', strtotime($row1['submit_date'])); ?></td>
<?php } ?>
</tr> <?php
?>
</table>
</div>
<?php
} ?>

Drop-down values

I got two php files the Add.php and Edit.php
In Add.php. A drop-down list of date and gender.
<tr>
<td width="400" id="caption" style="text-align:right;">Birthdate</td>
<td>
<select id="monthID" name="month">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select id="dayID" 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>
<select id="yearID" name="year">
<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="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>
</select>
</td>
</tr>
<tr>
<td width="400" id="caption" style="text-align:right;">Gender</td>
<td id="caption" style="text-align:left;">
<select name="gender">
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</td>
</tr>
If I choose April 3 2010 and Female in the drop-downs. And insert it in my table_1
Assume this are drop-downs
Birthdate: April 3 2010
Gender: Female
Now, when I want to update the record(s) in Edit.php the drop-down value should be also the same
Birthdate: April 3 2010
Gender: Female
But instead it gives me this
Birthdate: January 1 2013
Gender: Male
It seems like a default value whenever I visit in Edit.php. (January 1 2013 Male - are the first items in the dropdowns)
How can I make [April 23 2013 Female] appear in my drop-down Instead of the first values that I didn't choose.
Thanks and sorry for the title I can't think for a good title for this.
Use an if statement to compare each value with your record and then add "selected" to this option
here is the basic concept hope you catch the idea
<?php
$array = array(1=>"January",
2=>"February",
3=>"March",
4=>"April",
5=>"May",
6=>"June",
7=>"July",
8=>"August",
9=>"September",
10=>"October",
11=>"November",
12=>"December");
$stored_data = "2";
foreach($array as $key => $val) {
if($stored_data == $key) {
echo "<option value='$key' selected='1'>$val</option>";
} else {
echo "<option value='$key'>$val</option>";
}
}
?>

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