简体   繁体   中英

how to correctly echo the href in php with value on it?

my echo shows unexpected T_VARIABLE and i dont know how to correctly echo my href please help me

echo '<a href="'.edit_account.php?id=$val['id'].'"  class="btn btn-xs btn-info">Edit</a>'

please help me im a beginner

Replace

'<a href="'.edit_account.php?id=$val['id'].'"  class="btn btn-xs btn-info">Edit</a>'

with

'<a href="edit_account.php?id='.$val['id'].'"  class="btn btn-xs btn-info">Edit</a>'

You started concatenation from the wrong place

You have incorrect use of string concatenation. Also, better use double quotes when forming the link so that you wouldn't need separate concatenation for PHP variables.

<?php

echo "<a href='/edit_account.php?id=$val[id]'  class='btn btn-xs btn-info'>Edit</a>";

I believe the code should look something like this

<a href="<?php echo $your_url_variable?>" > your anchor text here </a>

or

echo '<a href="'.$your_url_variable.'">';

depending on where you want to insert the url

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM