Plicas and IF php problem

Asked

Viewed 161 times

-3

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

I have that 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>
  • Wow... 6 down-votes just because the guy doesn’t know PHP. It’s hard to learn something new these days! =\

  • pqp. That’s dirty. Dude, just a hint, type echo first ' '; and in there you put HTML. This way you won’t get confused.

3 answers

7

Follow "fix" to 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>';

Since you apparently have no experience with PHP, avoid breaking the lines so you don’t get confused. Try to use an echo for each line, and open and close the plicas (summits, actually) correctly.

2

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

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>";

-1

Correct Syntax: 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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.