PHP Error Parse error: syntax error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING [closed]

0

I need to do a validation, if it's true goes to a link and if it's fake it goes somewhere else. my code is next.

<a href='<?php if($dado['st_nome'] =="FINALIZADO")
{echo "dashboard.php?link=17&id=<?php echo $dado["op_id"];?>";}
else{ echo '#';}?>'>

But it's coming back to me

PHP Parse error: syntax error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in E:\home\gigaclima\Web\giga_proj\paginas\listas\listar_op.php on line 50

Something in the code is generating a conflict that I can not identify.

    
asked by anonymous 17.08.2016 / 16:13

3 answers

4

Since you're already in PHP you do not need to open again, do you understand?

The correct would look like this:

<a href='<?php if($dado['st_nome'] =="FINALIZADO")
{echo "dashboard.php?link=17&id={$dado['op_id']}";}
else{ echo '#';} ?>'>

But I advised you to do this:

<?php
if( $dado['st_nome'] == "FINALIZADO" )
    $link = "dashboard.php?link=17&id=".$dado["op_id"];
else 
    $link= "#";
?>
<a href='<?php echo $link; ?>'>

To have the minimum of PHP in the middle of HTML. It's less confusing.

    
17.08.2016 / 16:17
2

I think you can still use a ternary as an option:

<?php
     $dado['st_nome'] == "FINALIZADO" ?  $link = "dashboard.php?link=17&id=".$dado["op_id"]: $link= "#"; 
?>

<a href='<?php echo $link; ?>'>
    
17.08.2016 / 16:53
1

Your code was spelled wrong, it follows the correctness of the code, with no change in its style:

<a href='<?php
    if($dado['st_nome'] =="FINALIZADO"){
        echo "dashboard.php?link=17&id=" .  $dado["op_id"]; 
    }else{ 
        echo '#';        
    } ?>'>Link</a>

It also has the version posted by Jorge B., which separates PHP from HTML and leaves the code cleaner.

    
17.08.2016 / 16:22