Conditional if block not having effect on my code in php

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
michaelagbogidi
New php-forum User
New php-forum User
Posts: 1
Joined: Mon Jan 06, 2020 10:31 am

Mon Jan 06, 2020 10:46 am

I have a calendar system I wrote for a booking system that, via ajax, loops through the days of the month and displays them showing available slots for each day of each month for each year. For the current year, it only displays the available months left including the current month.

Now I tried to amend the script to display "Booking Closed" for the current day and days past for the current month of the current year.

The problem I have now is that I can't get it to work like I want.

Thinking about it, the logic is that if it is the current year and for the current month, the current days and past days should read "Booking Closed" so, I created an "if" conditional block that states that for the current year and the current month, the past days should read "Booking Closed" but other days should be available, and other months should also be available.

But the issue is it reads "Booking Closed" for the same past days for every month for every year. Its like the conditional if block is not coming into play.

I have tried everything but can't figure it out. I believe it will be a small thing i am missing, but can't seem to figure it out.

So any help is appreciated. Like they say, two heads are better than one.

My code below:

if($_POST){

date_default_timezone_set('Africa/Lagos');
$date = date('Y-m-d');

$cimslots = "30";
$year = $_POST['year'];
$month = $_POST['month'];
$days = date('j');
$daysinmonth = date('t',mktime(0,0,0,$month,1,$year));
$curday = date('d');
$curmonth = date('n');
$curyear = date('Y');
}

<div id="calendar-display">
<?Php for($day = 1; $day <= $daysinmonth; $day++){

$checkday = date("l", mktime(0, 0, 0,$month,$day,$year));

$query = "SELECT cimID, screeningdate, paymentstatus FROM cimbooking WHERE YEAR(screeningdate)=? AND MONTH(screeningdate)=? AND DAY(screeningdate)=?";
$stmt = $connQlife->prepare($query);
$stmt->bind_param('sss', $year, $month, $day);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($cimID, $screeningdate, $paymentstatus);
$stmt->fetch();
$totalnumrows = $stmt->num_rows;
$stmt->close();

$availableslots = $cimslots - $totalnumrows;


$querypubhols = "SELECT phdateID, phdate, phdetail FROM pubhols WHERE YEAR(phdate)=? AND MONTH(phdate)=? AND DAY(phdate)=?";
$stmtpubhols = $connQlife->prepare($querypubhols);
$stmtpubhols->bind_param('sss', $year, $month, $day);
$stmtpubhols->execute();
$stmtpubhols->store_result();
$stmtpubhols->bind_result($phdateID, $phdate, $phdetail);
$stmtpubhols->fetch();
$stmtpubhols->close();
?>

<div class="calendarcont">
<?Php if (($checkday != "Sunday")&&($checkday != "Saturday")&&($phdate == "")) { ?>
<div class="calendarheadercont">
<div class="calendarday"><?Php echo date("l", mktime(0, 0, 0,$month,$day,$year)); ?></div>
</div>
<div class="clear_1"></div>
<div class="calendarsubcont">
<div class="calendardatecont">
<div class="calendarmonth"><?Php echo date("M", mktime(0,0,0, $month,$day,$year)); ?></div>
<div class="calendardate"><?Php echo date("j", mktime(0,0,0,$month,$day,$year)); ?></div>
</div>
<?Php if (($year = $curyear)&&($month = $curmonth)&&($day > $curday)){ ?>
<div class="calendartextcont">
<?Php if ($availableslots > 5){ ?>
<div class="calendartextg">Available slots: <?Php echo $availableslots; ?></div>
<?php } ?>
<?Php if (($availableslots >= 1)&&($availableslots <= 5)) { ?>
<div class="calendartexto">Available slots: <?Php echo $availableslots; ?></div>
<?php } ?>
<?Php if ($availableslots <= 0){ ?>
<div class="calendartextr">No Slots Available!</div>
<?php } ?>
</div>
<?Php if ($availableslots >= 1){ ?>
<label class="calendarcheckbox">Select
<input type="checkbox" name="screening" id="screening" value="<?Php if ($screeningdate=="") {echo date('Y-m-d', mktime(0,0,0,$month,$day,$year)); }else{ echo $screeningdate; } ?>">
<span class="checkmark"></span>
</label>
<?php } ?>
<?php } else { ?>
<div class="calendartextcont">
<div class="calendartextr">Booking Closed!</div>
</div>
<?php } ?>
</div>
<?Php }else if ($checkday == "Sunday"){ ?>
<div class="calendarheadercont">
<div class="calendarday"><?Php echo date("l", mktime(0, 0, 0,$month,$day,$year)); ?></div>
</div>
<div class="clear_1"></div>
<div class="calendarsubcont">
<div class="calendardatecont">
<div class="calendarmonth"><?Php echo date("M", mktime(0,0,0, $month,$day,$year)); ?></div>
<div class="calendardate"><?Php echo date("j", mktime(0,0,0,$month,$day,$year)); ?></div>
</div>
<div class="calendartextcont">
<div class="calendartextr">Closed On Sundays!</div>
</div>
</div>
<?Php }else if ($checkday == "Saturday"){ ?>
<div class="calendarheadercont">
<div class="calendarday"><?Php echo date("l", mktime(0, 0, 0,$month,$day,$year)); ?></div>
</div>
<div class="clear_1"></div>
<div class="calendarsubcont">
<div class="calendardatecont">
<div class="calendarmonth"><?Php echo date("M", mktime(0,0,0, $month,$day,$year)); ?></div>
<div class="calendardate"><?Php echo date("j", mktime(0,0,0,$month,$day,$year)); ?></div>
</div>
<div class="calendartextcont">
<div class="calendartextr">No Screening!</div>
</div>
</div>
<?Php }else if ($phdate != ""){ ?>
<div class="calendarheadercont">
<div class="calendarday"><?Php echo date("l", mktime(0, 0, 0,$month,$day,$year)); ?></div>
</div>
<div class="clear_1"></div>
<div class="calendarsubcont">
<div class="calendardatecont">
<div class="calendarmonth"><?Php echo date("M", mktime(0,0,0, $month,$day,$year)); ?></div>
<div class="calendardate"><?Php echo date("j", mktime(0,0,0,$month,$day,$year)); ?></div>
</div>
<div class="calendartextcont">
<div class="calendartextr"><?Php echo $phdetail; ?></div>
</div>
</div>
<?Php } ?>
</div>
<?Php } ?>
</div>
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 929
Joined: Mon Feb 22, 2016 5:52 pm

Mon Jan 06, 2020 12:28 pm

The code that you have posted will not execute.

Turn on display_errors in your php.ini file while you are developing so that you can see where the PHP errors are occurring.

When posting code, use the </> code button and format it:

Code: Select all

if ($_POST) {

  date_default_timezone_set('Africa/Lagos');
  $date = date('Y-m-d');

  $cimslots = "30";
  $year = $_POST['year'];
  $month = $_POST['month'];
  $days = date('j');
  $daysinmonth = date('t',mktime(0,0,0,$month,1,$year));
  $curday = date('d');
  $curmonth = date('n');
  $curyear = date('Y');
}
---- here's an error that will prevent the script from executing ----
<div id="calendar-display">
First deal with the syntax errors, then look for the logic errors; the last thing that will be wrong is PHPs execution of an if statement.
Post Reply