Error in getting the <a href = ' '> value

312 Views Asked by At

I am trying to get the value of an anchor tag using PHP code. When I click the hyperlink, however, I am not getting the value.

My code is as follows:

<?php
    $gettingevents = "SELECT event_name FROM events";
    $resultgettingevents = mysqli_query($con,$gettingevents) or die(mysqli_error($con));

    while($getevents = mysqli_fetch_assoc($resultgettingevents)){
        $gettablenames = $getevents['event_name'];
        echo '<a id="events" href="registeredevents.php?tablename='.$getevents['event_name'].'">'.$gettablenames.'</a>';

        if(isset($_GET['tablename'])){
            $clickedtable =$_GET['tablename'];
            echo "the clicked table is ".$clickedtable;
        }else{
            echo "";
        }

    }
?>

I am getting the following error:

undefined index: tablename in

What is wrong with my code? How can I get the hyperlink value?

1

There are 1 best solutions below

10
On BEST ANSWER

Try

<?php
    $gettingevents = "SELECT event_name FROM events";
    $resultgettingevents = mysqli_query($con,$gettingevents) or die(mysqli_error($con));
    while($getevents = mysqli_fetch_assoc($resultgettingevents)){
        $gettablenames = $getevents['event_name'];
        echo '<a id="events" href="registeredevents.php?tablename='.$getevents['event_name'].'">'.$gettablenames.'</a>';
        if(isset($_GET['tablename'])){    
          $clickedtable =$_GET['tablename'];
        }
    }
    ?>