Redirect user through another variable, keeping my background - PHP

Asked

Viewed 29 times

-1

good afternoon!

Is it possible for me to put one href to redirect to another page within a variable?

I have a simple listing where I display the name, and on the side I have a button that redirects to an editing page, I would like to put that same function of button, where I display the name, it is possible?

My code where I display the name: echo" <td>{$cont['nome']}</td>";

My button:

echo "
<td> 
<a href='edit_personal.php?id=".$cont['id']."&nome=".$cont['nome']." target='new_blank'></a> 
</td>";               

I tried, but it didn’t work...

  • Missing to close single attribute quotes href.

1 answer

0


The title of your question is a bit confusing, but if I understand your problem is only with concatenation.

The double quotes say to the PHP to start the interpolation and this costs more appeal. The ideal would be to use the single quote when interpolation is not used.

// Exemplo utilizando concatenação
echo '<td><a href="edit_personal.php?id=' . $cont['id'] . '&nome=' . $cont['nome'] . '" target="new_blank">' . $cont['nome'] . '</a></td>';

// Exemplo utilizando interpolação
echo "<td><a href='edit_personal.php?id={$cont['id']}&nome={$cont['nome']}' target='new_blank'>{$cont['nome']}</a></td>";
  • Tested? Gave some error?

  • I’m trying, but it wasn’t, I think it’s my mistake... <td style='background-color:$cor'><a href='edit_personal.php?id='.$cont['id'].'&nome='.$cont['nome']. '' target='new_blank'><b>'.$cont['nome'].'</b></a></td>"; I just forgot to put a few things in the post... (already has an echo on top)

  • You have some concatenation errors, why didn’t you copy and paste the code I put in? It’s totally different.

  • I did, I just added the background to the td and took the echo because I had it on

  • That is, in this small change you made, you forgot to replace the double quotes with the single ones. echo " for echo ' and uses the response code.

  • That way it worked, though, mine style='background-color:$cor' IS NOT WORKING...echo ' <td style="background-color:$cor"><a href="edit_relatorio.php?codigo_relatorio='.$cont['codigo_relatorio'].'&paciente='.$cont['paciente']. '" target="new_blank">&#xA; <b>'.$cont['paciente'].'</b></a></td>';

  • Try the following: <td style="background-color:' . $cor . ' ">. Updates your question with this color snippet that I update the answer to get the full code for you.

  • It worked, thank you!

Show 3 more comments

Browser other questions tagged

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