How to include PHP code in an URL

Now I have hard coded the following, I want to pass two values to the index.php

<a target="_blank" rel="nofollow" href="index.php?vaccineid=VI 7038&patientid=PN001">
<?php echo $row['vaccine'];?></a>

I have tried to replace it with dynamic code, but in vain

<a target="_blank" rel="nofollow" href="index.php?vaccineid =<?php echo "$row['vaccineid']";?>
 &patientid=<?php echo "$_SESSION['abc']"; ?>"><?php echo $row['vaccine'];?></a>

Any ideas? Thanks

When using array indexing inside a double-quoted string, don’t put quotes around the index. So all you need to do is change

echo "$row['vaccineid']"
echo "$_SESSION['abc']"


// Remove single-quotes around keys ['key'] => [key]
echo "$row[vaccineid]"
echo "$_SESSION[abc]"

Or remove the double-quotes since you are outputting just the array value:

echo $row['vaccineid']
echo $_SESSION['abc']

try using html entities

such as passing in things like this in

&lt;?php echo "blablabla"; ?> 

which gives the value <?php echo “blablabla”; ?>

I would maybe think of using http_build_query() from the manual:

$values = array(
    'vaccineid' => $row['vaccineid'],
    'patientid'=> $_SESSION['abc']
<a target="_blank" rel="nofollow" href="index.php?<?php echo http_build_query($values) ?>"><?php echo  $row['vaccineid'] ?></a>

Check your array to make sure it’s what you expect:


One final note, if you have the $_SESSION[‘abc’] in the session, don’t send it via GET, just retrieve it from the session at the time you process the vaccineid on the next page.

Your variable not parse inside double quotes.

<a target="_blank" rel="nofollow" href="index.php?vaccineid=<?php echo urlencode($row['vaccineid']));?>&patientid=<?php echo $_SESSION['abc']; ?>"><?php echo $row['vaccine'];?></a>

Edit : Also you need to encode the vaccineid since it contains contains blank spaces.