What I'd like to do is store the "selected" value of the drop down box in a DB. At the moment the selected value for the drop down list is pulled from the DB. Now what I want to happen is if I don't want to change that specific option from the drop-down list then the variable gets put back into the DB. At the moment if I don't select anything then my the value that is put back into the DB is 0.
My code is as follows:
The drop-down list
<?php
// open connection to MySQL server
$connection = mysql_connect('localhost', 'username', 'password')
or die ('Unable to connect!');
//select database
mysql_select_db('database') or die ('Unable to select database!');
//create and execute query
$query = "SELECT day(farmFullStartDate) FROM rates";
$result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
//create selection list
echo "<select name='startDay' class='eventDay' id='startDay'>\n";
while($row = mysql_fetch_row($result))
{
echo "<option selected='selected'>$row[0]</option>";
}
echo "<option>01</option>";
echo "<option>02</option>";
echo "<option>03</option>";
echo "<option>04</option>";
echo "<option>05</option>";
echo "<option>06</option>";
echo "<option>07</option>";
echo "<option>08</option>";
echo "<option>09</option>";
echo "<option>10</option>";
echo "<option>11</option>";
echo "<option>12</option>";
echo "<option>13</option>";
echo "<option>14</option>";
echo "<option>15</option>";
echo "<option>16</option>";
echo "<option>17</option>";
echo "<option>18</option>";
echo "<option>19</option>";
echo "<option>20</option>";
echo "<option>21</option>";
echo "<option>22</option>";
echo "<option>23</option>";
echo "<option>24</option>";
echo "<option>25</option>";
echo "<option>26</option>";
echo "<option>27</option>";
echo "<option>28</option>";
echo "<option>29</option>";
echo "<option>30</option>";
echo "<option>31</option>";
echo "</select>";
?>
And this is the php that updates the DB
// open connection to MySQL server
$connection = mysql_connect('localhost', 'username', 'password')
or die ('Unable to connect!');
//select database
mysql_select_db('database') or die ('Unable to select database!');
//define variables
$startDay = $_POST['startDay'];
$startMonth = $_POST['startMonth'];
$startYear = $_POST['startYear'];
$startDate = $startYear."".$startMonth."".$startDay;
$endDay = $_POST['endDay'];
$endMonth = $_POST['endMonth'];
$endYear = $_POST['endYear'];
$endDate = $endYear."".$endMonth."".$endDay;
$luxury = $_POST['luxury'];
$orchid = $_POST['orchid'];
//create query
$query = "UPDATE rates SET farmFullStartDate = '$startDate', farmFullEndDate = '$endDate', farmFullLuxury = '$luxury', farmFullOrchid = '$orchid'";
//$query = "INSERT INTO rates (farmFullStartDate, farmFullEndDate, farmFullLuxury, farmFullOrchid) VALUES ('$startDate', '$endDate', '$luxury', '$orchid')";
//execute query
$result = mysql_query($query)
or die ("Error in query: $query. " . mysql_error());
// close connection
mysql_close($connection);
Any help would be greatly appreciated.
P.S. If I haven't explained myself well enough then here's an example situation:
I select 05 from startDay and hit submit. The page refreshes and 5 is displayed in the startDay drop-down list. Now I don't want to change startDay but I want to change other fields in the form so I do so and hit submit. What I have changed gets sent to the DB and 0 gets sent to the DB for startDay. What should be happening is it should be sending 5 to the DB.