2016-12-22 7 views
-1

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.<a href = ' '> 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?

+0

why you used '$clickedtable =$_GET['tablename']' this line at the end of while loop? –

+0

ermmm to get the hyperlink value... – Madhi

+2

you also need to remove the space in 'registeredevents.php?tablename =' - besides putting the GET array first and checking if it's set/not empty –

답변

0

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

i tried..it doesn't enter into if [email protected] – Madhi

+0

the 'if ' will be executed when you actually visit on of those generated urls,for the first time you are visiting the 'url = registeredevents.php'.But when you click on the url whcih is genarated then your url will look like 'url = registeredevents.php?tablename=xyz'. Then the '$clickedtable = xyz' – Abhishek

+0

i clicked the link and i echoed **$clickedtable** it is not printing..it's not entering into if loop..... – Madhi