The question is pretty difficult to ask, but I'll try and be as clear as possible. Pretty much I have created a form where a user submits a request and in my SQL table it autogenerates the time for when the user clicks submit. The code for the SQL part is:
request_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
In my form I have a html calender input, in the format YY-MM-DD and I have a separate time input in the format HH:MM. I am pretty much trying to ensure that a date earlier than the current date cannot be selected, but I am having a bit of a hard time.
Here is my php/html code for reference:
<html>
<head>
<title>ShipOnline Request System</title>
</head>
<body>
<h2>ShipOnline System Request Page</h2>
<fieldset>
<p>Item Information:</p>
<fieldset>
<form method="post">
<p><label for="description">Description: <input type="text" name="description" id="description"></label></p>
<p><label for="weight">Weight: </label>
<select name="weight" id="weight">
<option value= "">Select Weight</option>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
</select></p>
<p>Weight is charged at a flat rate of $10 for 0-2Kg and an additional $2 per kg, with a max of 20kg.</p>
</fieldset>
<p>Pick-up Information:</p>
<fieldset>
<p><label>Address: <input type="text" name="address" id="address"></label></p>
<p><label>Suburb: <input type="text" name="suburb" id="suburb"></label></p>
<p><label for="Date">Preferred Date: </label>
<input type="date" name="date"></p>
<p><label for="time">Preferred Time: </label>
<input type="time" name="time" min="07:30" max="20:30"></p>
<p>Time must be between 7:30am and 8:30pm</p>
</fieldset>
<p>Delivery Information</p>
<fieldset>
<p><label>Receiver Name: <input type="text" name="name" id="name"></label></p>
<p><label>Address: <input type="text" name="address1" id="address"></label></p>
<p><label>Suburb: <input type="text" name="suburb1" id="suburb"></label></p>
<p><label for="state">State: </label>
<select name="state" id="state">
<option value="">Select State</option>
<option value="vic">VIC</option>
<option value="nsw">NSW</option>
<option value="tas">TAS</option>
<option value="sa">SA</option>
<option value="act">ACT</option>
<option value="wa">WA</option>
<option value="nt">NT</option>
</select></p>
</fieldset>
<p><input type= "submit" value="Request" ></p>
</fieldset>
</form>
<?php
$custnum= $_GET['custno'];
if(isset($_POST['description']) && isset($_POST['weight']) && isset($_POST['address']) && isset($_POST['suburb']) && isset($_POST['date']) && isset($_POST['time']) && isset($_POST['name']) && isset($_POST['address1']) && isset($_POST['suburb1']) && isset($_POST['state'])) {
if (empty($_POST['description']) ||
empty($_POST['weight']) ||
empty($_POST['address']) ||
empty($_POST['suburb']) ||
empty($_POST['date']) ||
empty($_POST['time']) ||
empty($_POST['name']) ||
empty($_POST['address1']) ||
empty($_POST['suburb1']) ||
empty($_POST['state'])) {
die('Please fill all required fields!');
}
$DBConnect = @mysqli_connect("", "", "", "")
Or die ("<p> Unable to connect to the database server.</p>". "<p>Error code". mysqli_connect_errno().":".mysqli_connect_error()). ",/p>";
$description= mysqli_real_escape_string($DBConnect, $_POST['description']);
$weight= mysqli_real_escape_string($DBConnect, $_POST['weight']);
$address= mysqli_real_escape_string($DBConnect, $_POST['address']);
$suburb= mysqli_real_escape_string($DBConnect, $_POST['suburb']);
$date = mysqli_real_escape_string($DBConnect, $_POST['date']);
$time= mysqli_real_escape_string($DBConnect, $_POST['time']);
$name= mysqli_real_escape_string($DBConnect, $_POST['name']);
$address_one= mysqli_real_escape_string($DBConnect, $_POST['address1']);
$suburb_one=mysqli_real_escape_string($DBConnect, $_POST['suburb1']);
$state= mysqli_real_escape_string($DBConnect, $_POST['state']);
$price= max($weight - 2, 0)*2 + 10;
$requestDate= mysqli_query($DBConnect, 'SELECT request_date FROM request');
$totaltime= $date."".$time.":00";
if ($requestDate>$totaltime) {
die("Pick up Time must be at least 24 hours after request is sent!");
}
$SQLString= "INSERT INTO request (customer_number, item_description, weight, pickup_add, suburb, pickup_date, pickup_time, name, address, receiver_suburb, state) VALUES ('$custnum', '$description', '$weight', '$address', '$suburb', '$date','$time' ,'$name', '$address_one', '$suburb_one', '$state')";
if(mysqli_query($DBConnect, $SQLString)){
$reqno= $DBConnect -> insert_id;
echo "Thank you! Your request number is $reqno. The cost is $$price. We will pick-up the item at $time on $date.";
}else{
echo "ERROR";
}
mysqli_close($DBConnect);
}
?>
</body>
</html>
Any help would be appreciated thank you!