1

I have a strange issue in my site conception...

I try to create a select with 3 input, one for day, one for month and one for year. The year input work clean, but, if I try that for day:

for($i = 1; $i <= date('t'); $i++) {
  if ($i < 10) {
    $i = '0'. $i;
  }
  if ($i = date('d')) {
    echo '<option selected>'. $i .'</option>';
  } else {
    echo '<option>'. $i .'</option>';
  }
}

This bug totally my navigator (Firefox up to date version) and I don't understand why...

Claire Nielsen
  • 1,881
  • 1
  • 14
  • 31
MajorKurk
  • 26
  • 1
  • 5

1 Answers1

0

Change:-

if ($i = date('d')) {//it's assignment not comparison

To:-

if ($i == date('d')) { //or if ($i === date('d')) { now it's comparison

Output:-https://eval.in/860475 OR https://eval.in/860476

Reference:- The three different equals

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98