I'm currently working on an assignment that involves a lot of php stuff. So basically what I have is a website that allows you to buy movie tickets, you create an account, sign in to access the movies, choose the day and time, quantity and then checkout. I'm currently stuck on trying to retrieve the day and time.
This code is the php page for after the user has signed in and is currently choosing what movie they want and all of their options.
//Sign In Page
$query = 'SELECT * FROM project_movies ORDER BY title;';
$results = $conn->query($query);
if ($results && $results->num_rows > 0) {
$n = $results->num_rows;
echo '<form method="post" action="project_review.php"><table border="1">';
echo '<tr><th>Movies</th><th>Synopsis</th><th>Day</th><th>Time</th><th>Quantity</th><th>Add to Cart</th></tr>';
for ($i = 0; $i < $n; $i++) {
$movies = $results->fetch_assoc();
echo "<tr><td>$movies[title]<br /><img src='$movies[pathname]'></td><td>$movies[synopsis]</td><td>";
//Select Day of Week
$days = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
$length = count($days);
for ($j = 0; $j < $length; $j++) {
echo "<input type='checkbox' value='$days[$j]' name='day'>
<label for='$days[$j]'>$days[$j]</label><br />";
}
echo "</td><td>";
//Select Time
$time = array('12:00','3:00','6:00','9:00');
$length = count($time);
for ($m = 0; $m < $length; $m++) {
echo "<input type='checkbox' value='$time[$m]' name='time'>
<label for='$time[$m]'>$time[$m]</label><br />";
}
echo "</td><td>";
//Select Quantity of Tickets
echo "Kids $3 <input type='number' value='kids' name='kids' style=;width:35px;'><br />
Adults $9 <input type='number' value='adult' name='adult' style=;width:35px;'><br />
Seniors $5 <input type='number' value='senior' name='senior' style=;width:35px;'>";
echo "</td><td><input type='checkbox' name='checkout[]' value='$movies[mid]'";
echo "></td></tr>";
}
echo '</table><input type="submit" value="Checkout"></form>';
}
This section of code is from the review php page which is what will show the user what they chose.
//Review Page
$_SESSION['checkout'] = $_POST['checkout'];
$_SESSION['day'] = $_POST['day'];
$_SESSION['time'] = $_POST['time'];
echo '<p>Movie tickets in your cart:</p>';
// connect to MySQL server
$conn = new mysqli($hn, $user, $passwd, $db);
if ($conn->connect_error)
die($conn->connect_error);
$n = count($_SESSION['checkout']);
echo '<ul>';
for ($i = 0; $i < $n; $i++) {
$mid = $_SESSION['checkout'][$i];
$day = $_SESSION['day'][$j];
$time = $_SESSION['time'][$m];
$query = "SELECT title FROM project_movies WHERE mid = $mid;";
//echo $query;
$result = $conn->query($query);
if ($result && $result->num_rows > 0) {
$movies = $result->fetch_assoc();
echo '<li>' .$movies['title'] . '</li>';
echo '<p> →' .$day. ' at ' .$time. '</p>';
So far all I have working is the ability to see which movie was chosen, multiple of them can be chosen and they'll show up. If I select a day and time for only one movie, then it'll show up correctly. However, when I choose a second movie with a second set of day and time choices, it will just print out that day and time for both movies.
Here is the link to the page, the login I have set for now is
User: admin
Pass: 123456