I'm new to php. I have a dropdown menu in my form and the dropdown options are coming from a database and I'm trying to insert the selected options in the dropdown menu to a separate table in my database. The query seems to be getting executed but the team name values are not being inserted into the database. This is the code for the form. Any help is much appreciated!
<form class="form-register" method="POST" enctype="multipart/form-data">
Match Type
<select class="form-control" name="MatchType" value="Match Type">
<option value="Select one">Select One</option>
<option value="T20">Twenty20 Match</option>
<option value="OneDay">One-Day Match</option>
<option value="Test">Test Match</option> </select>
Home Team
<?php
mysql_select_db('cricket_system');
$sql = "SELECT TeamName FROM teams";
echo "<select class='form-control' name='Team1' value='Team1'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='". $row['TeamName']."'>". $row['TeamName']."</option>";
}
echo "</select> ";
?>
Away Team
<?php
mysql_select_db('cricket_system');
$sql1 = "SELECT TeamName FROM teams";
$result1 = mysql_query($sql1);
echo "<select class='form-control' name='Team2' value='Team2'>";
while ($row = mysql_fetch_array($result1)) {
echo "<option value='". $row['TeamName']."'>". $row['TeamName']."</option>";
}
echo "</select> ";
?>
Date (yyyy/mm/dd)
<input type="text" id="Date" name="Date" class="form-control" placeholder="Date (yyyy/mm/dd)" required>
<br><button class="signupbutton" type="submit" name="submit" >Add Match</button> <br> <br>
</form>
<?php
include('includes/database.php');
mysql_select_db('cricket_system');
if(isset($_POST['submit'])){
$Team1 = $_POST['Team1'];
$Team2 = $_POST ['Team2'];
$MatchType = $_POST['MatchType'];
$insert = "INSERT INTO matches (Team1, Team2, Date, MatchType) values
('$Team1', '$Team2', '$Date', '$MatchType')";
$add = mysql_query($insert);
if ($add) {
echo "<script>alert('Match has been successfully added.')</script>";
}
else {
echo mysql_error();
}
}
mysql_close();
?>