Open chieota opened 4 years ago
Inside this if statement https://github.com/chieota/restaurant-research/blob/fd4e4768ed2d24154f9dbb26898a75ac17f8f0a2/admin/reservation_action.php#L12
You put a condition that checks if the number of person is less than one. Then if it is less than one, you redirect the page back in add_reservation.php with the users last form inputs. Then you also need to display the last input back.
See example below.
if($_GET['action'] == 'add'){
$date = $_POST['date'];
$number_of_people = $_POST['number_of_people'];
$restaurant_id = $_POST['restaurant_id'];
//recommendation
if($restaurant_id > 0){
echo "<script>window.location.replace('reservations.php?date=$date&number_of_people=$number_of_people&restaurant_id=$restaurant_id');</script>";
}
$result = $reservation->save($restaurant_id,$date,$number_of_people,$_SESSION['user_id']);
if($result){
echo "<script>window.location.replace('reservations.php');</script>";
}else{
echo "Error!!";
}
}
Before the line below add the recommended code https://github.com/chieota/restaurant-research/blob/fd4e4768ed2d24154f9dbb26898a75ac17f8f0a2/admin/add_reservation.php#L8
See example.
<?php
session_start();
require_once "header.php";
require_once "../classes/Restaurant.php";
$restaurant = new Restaurant;
$id = $_GET['restaurant_id'];
//recommended
$date = '';
$number_of_people = '';
if(isset($_GET['date'])){
$date = $_GET['date'];
}
if(isset($_GET['number_of_people'])){
$number_of_people= $_GET['number_of_people'];
}
$get_restaurant = $restaurant->selectOne($id);
?>
Then in you html code starting from the below modify you code. https://github.com/chieota/restaurant-research/blob/fd4e4768ed2d24154f9dbb26898a75ac17f8f0a2/admin/add_reservation.php#L22
See example.
<form action="reservation_action.php?action=add" method="post">
<input type="hidden" name="restaurant_id" value="<?php echo $_GET['restaurant_id']?>">
<div class="form-group">
<label>Restaurant Name</label>
<input type="text" class="form-control" placeholder="Restaurant Name" name="restaurant_name" value="<?php echo $get_restaurant['restaurant_name']; ?>" disabled>
</div>
<div class="form-group">
<label>Date</label>
<input type="date" class="form-control" name="date" value="<?php echo $date; ?>">
</div>
<div class="form-group">
<label>Number of person</label>
<input type="number" class="form-control" name="number_of_people" value="<?php echo $number_of_people; ?>">
</div>
<input type="submit" value="Add" name="action" class="btn btn-danger">
</form>
Hi thank you so much. I put condition for number of people. But it is not working. Am I wrong?
My bad the condition should be like this If($number_of_people < 1)
Regardless the number of people, the adding action is working..
Try this out. If((int)$number_of_people < 1)
Still the same. The number is saved even if it's less than 0.
solved!Thanks!!!! I replaced this code "$result = $reservation->save($restaurant_id,$date,$number_of_people,$_SESSION['user_id']);" inside "if($result){ echo ""; }"
I have a question about the page of making a reservation. Now we can make a reservation even if the number of people is less than 0. Please tell me where I can put the condition..