I'm fairly new to php and I'm having a hard time figuring out how to make a form where I can have multiple inputs and use php to input all the inputs into a sql table. I set up a table so that each row is a new entry, this way a schedule can be uploaded all at once, instead of 1 by 1.
Here is my current code:
html:
<table id="register">
<form action="processing_games.php" method="post"/>
<tr>
<td><p>Date<br>(m/dd/yy)</p></td>
<td><p>Time<br>(h:mm AM/PM)</p></td>
<td><p>Opponent</p></td>
<td><p>Location<br>(Rink Name)</p></td>
<td><p>Conference<br>Game?</p></td>
<td><p>Home or Away<br>Game?</p></td>
</tr>
<tr>
<td><input type="date" name="date"></td>
<td><input type="time" name="time"></td>
<td><input type="text" name="opponent"></td>
<td><input type="text" name="location"></td>
<td><input type="radio" name="conference" value="+"> Conference
<br>
<input type="radio" name="conference" value=""> Non-Conference </td>
<td><input type="radio" name="home_away" value=" vs "> Home
<br>
<input type="radio" name="home_away" value=" @ "> Away</td>
</tr>
<tr>
<td><input type="date" name="date"></td>
<td><input type="time" name="time"></td>
<td><input type="text" name="opponent"></td>
<td><input type="text" name="location"></td>
<td><input type="radio" name="conference" value="+"> Conference
<br>
<input type="radio" name="conference" value=""> Non-Conference </td>
<td><input type="radio" name="home_away" value=" vs "> Home
<br>
<input type="radio" name="home_away" value=" @ "> Away</td>
</tr>
</table>
<br><br>
<center>
<input type="submit" value="Submit"/>
</form>
php:
<?php
include '../connection.php';
$game_date = $_POST['date'];
$game_time = $_POST['time'];
$value3 = $_POST['opponent'];
$value4 = $_POST['location'];
$value5 = $_POST['conference'];
$value6 = $_POST['home_away'];
$value = date('n/j/y', strtotime($game_date));
$value2 = date('g:i A', strtotime($game_time));
$sql = "INSERT INTO schedule (date, time, opponent, location, conference, home_away) VALUES ('$value', '$value2', '$value3', '$value4', '$value5', '$value6')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
header("Location: http://www.rit.edu/sg/clubhockey/admin/complete.php");
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
mysqli_close($conn);
?>
Any help is appreciated.