<?php
//$game_id = ['gameid'];
$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$address = $_POST['address'];
$postal_code = $_POST['postalcode'];
$start_date = $_POST['startdate'];
$rental_days = $_POST['rentaldays'];
$borrow_game = $_POST['borrowgame'];
Variables are set here^!
$end_date = date('Y-m-d', strtotime($start_date.' + '.$rental_days.'days'));
How the end_date function works^!
$conn = mysqli_connect("localhost", "evansbwg_user", "1password1", "evansbwg_database");
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
Connection^!
$result = mysqli_query($conn, "SELECT * FROM tbl_games WHERE game_name = '$borrow_game'");
//$result_present = mysqli_query($conn, $result);
$num_rows = mysqli_num_rows($result);
if ($num_rows == 1)
{
$row2 = mysqli_fetch_array($result);
$id = $row2['game_id'];
Getting game_id to equal borrow_game^!
$sql_search = "SELECT * FROM tbl_rental WHERE game_id = '$id'
AND (start_date <= '$start_date' AND end_date >= '$end_date')
OR (start_date >= '$start_date' AND start_date <= '$end_date')
OR (end_date >= '$start_date' AND end_date <= '$end_date')
OR (start_date >= '$start_date' AND end_date <= '$end_date')";
$result1 = mysqli_query($conn, $sql_search);
$num = mysqli_num_rows($result1);
if ($num == 0)
{
$sql = "INSERT INTO tbl_rental (game_id, first_name, last_name, address, postal_code, start_date, rental_days, borrow_game, end_date)
VALUE ('$id', '$first_name', '$last_name', '$address', '$postal_code', '$start_date', '$rental_days', '$borrow_game', '$end_date')";
Inserting the data into the table^!
if (mysqli_query($conn, $sql))
{
echo "New record created successfully";
}
else
{
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
}
while ($row = mysqli_fetch_array($result))
{
$id = $row['game_id'];
}
mysqli_close($conn);
?>
I have fixed my main problem however if any changes need to be made please suggest.