获取<a href=" "> value

时间:2016-12-22 19:01:18

标签: php mysql anchor

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 个答案:

答案 0 :(得分:0)

尝试

<?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'];
        }
    }
    ?>