Search code examples
phphtmlhrefdropdown

How do I pass the php variable through the href of the dropdown


I am fetching the email from the search bar and storing it in $first variable. Later I want this variable to be passed through the href=cn.php attribute. How can i do so? Also please note I am using bootstrap here, but skipped the inclusion text.

<?php
$first = $_GET['email'];
?>
<!doctype html>
<html lang="en">
<div class="dropdown text-center">
<br><br>
<br><br>
<button type="button" class="col-4 btn btn-primary dropdown-toggle" data- 
toggle="dropdown">Select the Subject</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="CN.php?email=' . $first . '">Computer 
Networks</a>
</div>
</div>
</body> 
</html>

Solution

  • Your code will look like-

    <?php
    $first = $_GET['email'];
    ?>
    <!doctype html>
    <html lang="en">
    <div class="dropdown text-center">
    <br><br>
    <br><br>
    <button type="button" class="col-4 btn btn-primary dropdown-toggle" data- 
    toggle="dropdown">Select the Subject</button>
    <div class="dropdown-menu">
    <a class="dropdown-item" href="CN.php?email=<?php echo $first;?>">Computer 
    Networks</a>
    </div>
    </div>
    </body> 
    </html>