Problem plicas and IF php

-4

Parse error: syntax error, unexpected 'if' (T_IF), expecting ',' or ';' in

I have this error in the second line of this code:

echo '<div id="tabs-2">
    <p>Ficha de Aptidão Médica Validade: if ($exibe['MedicaValidade']) { 
if (strtotime($exibe['MedicaValidade']) < time()) {
    echo '<span style="color:red">'.$exibe['MedicaValidade'].'</span>';
} else {
    echo $exibe['MedicaValidade'];
}
} else { 
echo 'N/D';}</p>
    
asked by anonymous 15.04.2014 / 18:00

3 answers

7

"Fix" for your code:

echo '<div id="tabs-2">';
echo '<p>Ficha de Aptidão Médica Validade:';
if ($exibe['MedicaValidade']) { 
   if (strtotime($exibe['MedicaValidade']) < time()) {
      echo '<span style="color:red">'.$exibe['MedicaValidade'].'</span>';
   } else {
      echo $exibe['MedicaValidade'];
   }
} else { 
   echo 'N/D';
}
echo '</p>';

As you apparently do not have experience with PHP, avoid breaking the lines so you do not get confused. Try to use an echo for each line, and open and close the plications (apices, actually) correctly.

    
15.04.2014 / 18:06
1

The errors are in the quotation marks and in the HTML code concatenated to PHP. Try this:

echo "<div id='tabs-2'> <p>Ficha de Aptidão Médica Validade: "; 
if ($exibe['MedicaValidade']) { 
    if (strtotime($exibe['MedicaValidade']) < time()) {
        echo "<span style='color:red'>" . $exibe['MedicaValidade']."</span>";
    } else {
        echo $exibe['MedicaValidade'];
    }
} else { 
    echo "N/D";
}
echo "</p>";
    
15.04.2014 / 18:06
-1

Syntax Correct: you were putting everything mixed Html with PHP and can not ...

<?php
   echo '<div id="tabs-2"><p>Ficha de Aptidão Médica Validade:';
   if ($exibe['MedicaValidade']) { 
       if (strtotime($exibe['MedicaValidade']) < time()) 
       {
           echo '<span style="color:red">'.$exibe['MedicaValidade'].'</span>';
       } else {
           echo $exibe['MedicaValidade'];
       }
   } else { 
       echo 'N/D';
   }
   echo '</p></div>';
?>

Note: Beware of joining Html with PHP syntax realizes that a simple organization was enough to find the error.

    
15.04.2014 / 18:06