Table of database
Table #1- april
id | month | rent
-------------------
1 | null | null
Table #2- may
id | month |rent
-------------------
1 | null | null
HTML form codes
<form name="SelectPeriod" method="post" action="monthselect.php">
Select month:
<select name="month">
<?php
$monthName = array("JANUARY", " FEBRUARY", " MARCH", " APRIL", " MAY", " JUNE", " JULY", " AUGUST", " SEPTEMBER", " OCTOBER ", " NOVEMBER ", " DECEMBER ");
for ($i = 0; $i < count($monthName); $i++) {
$mn = 1 + $i;
if ($mn == date("m")) {
echo "<option selected value = " . $mn . ">" . $monthName[$i] . "</option>
";
} else {
echo "<option value = " . $mn . ">" . $monthName[$i] . "</option>
";
}
}
?>
</select>
<input type="text" name="rent" value="" placeholder="Enter rent input"/>
<input type="submit" name="selectmonth" value=" Go" /></form>
And here php code for insert into
<?php if (isset($_POST['selectmonth'])) {
$month=$_POST['month'];//name of drop-down
$rent = $_POST['rent'];//name of textbox
if ($month == 'APRIL') { //<---here is the problem how to compare with table
$sql = "INSERT INTO april (month, rent) VALUES('$month','$rent')";
$result = $con->query($sql);
if ($result === TRUE) {
echo 'Successfully Inserted';
} else {
echo 'There is a problem';
}
} elseif ($month == 'MAY') {
$sql = "INSERT INTO may (month, rent) VALUES('$month','$rent')";
$result = $con->query($sql);
if ($result === TRUE) {
echo 'Successfully Inserted';
} else {
echo 'There is a problem';
}
}}?>
I want know how to insert in to specific month table with compare to drop-down month value april and may. or Any alternate solution ?