Question

I am giving a link a specific id to tell apart some elements displayed in the same page, when I click the link and get into the page I want a String with "Laboratorio: X" displayed, the X is the number of the id.

I tried a couple of things but so far something that seems so simple is proving to be quite annoying.

Here is my code to give the id to the link(on a includes.php):

if ($row['estado'] == 1) {
       echo '<div class="box" id="lab'.$row['idlab'].'">
          <p id="labName">Lab #'.$row['codigolab'] . '</p>
          <p class="info"><a href="#" class="lnkInfo" id="lab-'.$row['idlab'].'">Info</p></a>
          <p class="THIS LINK"><a href="reservarLab.php?idlab='.$row['idlab'] .'"">Reservar</p></a>
          <input type="hidden" name="txtId" id="txtId" value="'.$row['idlab'].'">
      </div>';

    }

When I click a element it is correctly displaying a different id for each different one.

The problem is here in this code (on another page lab.php):

<label for="sltElijaLab">

      <?php

          $name= isset($_POST['idlab'])

           echo 'Laboratorio: '.$name.'.';

        ?>


     </label>

Honestly I only need it to show me the id next to that "Laboratorio" so any help is greatly appreciated.

Was it helpful?

Solution

isset() just checks to see if a variable is set and does not have a value of null. It does not return the value from that variable (if it is set and does not have a value of null).

Here's a change to your code that uses isset() to check to see if $_POST['idlab'] is set. If so, $name is assigned its value. If not, $name is assigned "Unknown".

$name = isset($_POST['idlab']) ? $_POST['idlab'] : 'Unknown';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top