dlofrodloh
dlofrodloh

Reputation: 1744

Inserting PHP variable into HTML link properly

My code spits out candidate information and I want a link next to each candidate directing to ?loadcandidate=id

The data displays fine except it doesn't add the id in the link.. it's just blank (shows as ?loadcandidate=):

<?php
foreach ($cands as $cand):
?>

<?php htmlout($cand['id']); ?>-
<?php htmlout($cand['firstname']); ?>- 
<?php htmlout($cand['lastname']); ?>-
<?php htmlout($cand['email']); ?><br><br>

<a href="?loadcandidate="<?php echo $cand['id'];?>">load candidate</a> 

<?php
endforeach;
?>

What's wrong with my syntax?

Upvotes: 0

Views: 66

Answers (1)

patman
patman

Reputation: 2840

It's an HTML error. You end the href= attribute with " and then add the id.

<a href="?loadcandidate=<?php echo $cand['id'];?>">load candidate</a> 

Upvotes: 4

Related Questions