Error in php, with if

1

This is the error that appears to me,

  

An uncaught Exception was encountered       Type: ParseError

     

Message: syntax error, unexpected 'if' (T_IF)

     

Filename: C: \ xampp \ htdocs \ upa \ application \ controllers \ admin \ Users.php

     

Line Number: 53

and this is my code:

$action2 = "<td id='delboxbox".$r->id."'><label class='switch'><input type='checkbox'".
if ($r->state==2) {.'checked'.}." ><span class='slider'></span></label></td>";

It may be a minimal error, but I have looked and I have not found it.

    
asked by Andrés Cantillo 11.10.2018 в 17:41
source

2 answers

3

It's a bad idea to print html in php, but try this:

$action2 = "<td id='delboxbox".$r->id."'><label class='switch'><input type='checkbox' ".(($r->state==2) ? 'checked': '')." ><span class='slider'></span></label></td>";

that should solve your problem, Regards

    
answered by 11.10.2018 / 17:50
source
1

What happens is that you are not comparing in your if:

if ($r->state==2) // esto es comparacio

if ($r->state=2) // esto es igualacion
    
answered by 11.10.2018 в 17:47