我有这个if语句
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
$(document).on('submit', '#rentform', function () {
var data = $(this).serialize()
$.ajax({
type: 'POST',
url: 'newrent.php',
data: data,
success:(
function (data){$(".result").html(data)}
)
});
return false;
});
} )
$(document).ready(function () {
$('#rent').change(function(){
var x =($('#rent option:selected').data('sireal'))
$('#itemsn').val(x);
});
} )
</script>
<form method="post" id="rentform" action="" novalidate="novalidate">
<label for="item">REnter Name</label>
<select name="rnt_name" id="name_rent">
<option selected disabled>SELECT Renter Name</option>
<?php foreach ($nameq as $res) : ?>
<option value="<?= $res['user_name']?>"><?= $res['user_name'] ?></option>
<?php endforeach; ?>
</select>
<br/>
<br/>
<label for="item">Cameras</label>
<select name="item" id="rent">
<option selected disabled>SELECT ITEM</option>
<?php foreach ($rentq as $row) : ?>
<option value="<?= $row['item_brand']?>" data-sireal="<?= $row['s_n'] ?>"><?= $row['item_brand'] ?></option>
<?php endforeach; ?>
</select><br/>
<br/>
<input type="hidden" name="sn" id="itemsn" value="">
<label name="from_date">RENT FROM</label>
<input type="date" name="from_date"><br/>
<label name="from_hour">RENT FROM Hour</label>
<input type="time" name="from_hour"><br/>
<label name="to_date">RENT TO</label>
<input type="date" name="to_date"><br/>
<label name="to_hour">RENT FROM Hour</label>
<input type="time" name="to_hour"><br/>
<input type="submit" name="submit" value="Send Rent">
</form>
<div class="result">
</div>
if($_POST){
$name = $_POST['rnt_name'];
$item = $_POST['item'];
$fdate = $_POST['from_date'];
$fhour = $_POST['from_hour'];
$tdate = $_POST['to_date'];
$thour = $_POST['to_hour'];
$sn = $_POST['sn'];
$csheck = "SELECT * FROM rent";
$ckq = mysqli_query($link,$csheck);
foreach ($ckq as $res) {}
$count = "SELECT item_brand = '$item',s_n = '$sn',COUNT(*)
FROM item
WHERE status = 1 AND item_brand = '$item' AND s_n = '$sn'";
$cnt = mysqli_query($link,$count);
foreach ($cnt as $itm);
$itmq = "SELECT rent_item = '$item',COUNT(*)
FROM rent ";
$itemres = mysqli_query($link,$itmq);
foreach ($itemres as $missitm){};
if(($fdate >= $res['rent_from_d'] && $res['rent_to_d'] >= $tdate && $missitm['COUNT(*)'] >= $itm['COUNT(*)'] ) || ($fdate > $res['rent_from_d'] && $res['rent_to_d'] > $tdate && $fdate > $res['rent_from_d'] || $fdate <= $res['rent_to_d'] && $fhour <= $res['rent_to_t'] && $missitm['COUNT(*)'] >= $itm['COUNT(*)'] ) ) {
echo 'no good Item Rented To '.$res['renter'] ;
}else{
$newrent = "INSERT INTO rent (renter,rent_item,rent_from_d,rent_from_t,rent_to_d,rent_to_t)
VALUES ('$name','$item','$fdate','$fhour','$tdate','$thour')";
mysqli_query($link,$newrent);
echo 'pass';
}
这是表单提交后我在数据库中得到的内容
rent_id renter rent_item sn rent_from_d rent_from_t rent_to_d rent_to_t
115 dror x70 1234 2018-11-29 10:00 2018-11-29 14:00
我想做的是创建一个租金系统。我的问题是如何验证是否在两个日期和时间之间选择了项目。每次创建新的租金时,已选择的特定项目的状态都设置为0,因此该系统将不再可用。
谢谢。