Home > database >  Parse error on previous and next month calendar
Parse error on previous and next month calendar

Time:01-30

Hi everybody i'm currently following the tutorial of PhpWebTuts https://www.youtube.com/watch?v=adDHmMMSLJw 8 minute

I got this error Undefined variable $calendar whereas it's already defined

My PHP code

    $datetoday = date('Y-m-d');
$prev_month = date('m', mktime(0,0,0, $month-1, 1, $year));
$prev_year = date('Y', mktime(0,0,0, $month-1, 1, $year));
$next_month = date('m', mktime(0,0,0, $month 1, 1, $year));
$next_year = date('Y', mktime(0,0,0, $month 1, 1, $year));
$calendar .= "<a class='btn btn-primary btn-xs' href=?month=".$prev_month."&year=".$prev_year."'>Mois précedent</a> ";
$calendar .= "<a class='btn btn-primary btn-xs' href=?month=".date('m')."&year=".date('Y')."'>Mois précedent</a> ";
$calendar .= "<a class='btn btn-primary btn-xs' href=?month=".$next_month."&year=".$next_year."'>Mois précedent</a> ";
$calendar = "<table class='table table-bordered'>";
$calendar .= "<center><h2>$monthName $year</h2>";
$calendar .= "<tr>";

Edit = I found my error i forgot a dot on the 4th $calendar

CodePudding user response:

In the Video is:

$calendar = 'a';
$calendar .= 'b';

here they add string 'a' to an new variable $calendar. But you have

$calendar .= 'a';
$calendar .= 'b';

You try to add (.=) string 'a' to an not existing variable $calendar.

  •  Tags:  
  • Related