2

I am trying to get some information out of a query and into the values of some inputs, the parameter that it sends to display the specific information is a ID that is being send like this:

PHP on a includes file:

<a href="modificarLab.php?idlab='.$row['idlab'] .'">

<input type = "submit" value = "Modificar" class= "btnModificar" id = "btnModificar-'.$row['idlab'].'" 
style="position:absolute;left:170px;top:192px;"/>

</a>

When I click the above link it sends me to another page that reflects the idlab on the URL, so it shows idlab= X, where x depends on the idlab of the button clicked, this part seems to be working just fine.

The problem comes when trying to get the information into the inputs'values, in a example I used as reference they used the exact same syntax (including the part above with the href)and it is working, so I don't know what could I be doing wrong. This is how my code looks:

On the page the href refers to:

UPDATED php:

      <?php

      isset($_POST['lab']) ? $_POST['lab'] : 'Unknown';

            $result = getSpecificLabModify($_GET['lab']);

     ?>


  <form id="frmLabs" method="post">

  <?php
  if (isset($_GET['idlab'])){

        $result = getSpecificLabModify($_GET['idlab']);
     }
 ?>


<label for="txtCapacidad">Capacidad</label>
  <input type="text" name="txtCapacidad" id="txtCapacidad" value="<?php echo utf8_encode($result['capacidad'])?>">

  <label for="txtNumLab">Código de laboratorio</label>
  <input type="text" name="txtNumLab" id="txtNumLab" value="<?php echo utf8_encode($result['codigolab'])?>">
  <label for="txtUbicacion">Ubicación</label>
  <input type="text" name="txtUbicacion" id="txtUbicacion" value="<?php echo utf8_encode($result['ubicacion'])?>">

But instead of the values inside I am getting the error:

EDIT ERROR:

Notice: Undefined index: idlab in C:\wamp\www\Proyecto\modificarLab.php on line 66 Just in case the function to get the information is this one:

On the includes PHP file:

function getSpecificLabModify($pId){

    $query = "SELECT * FROM labs WHERE idlab=$pId";


    $result =  do_query($query);

    $row = mysql_fetch_assoc($result);


    return $row;
}

I've tried a lot of things but so far nothing has yielded any results. Thanks in advance.

9
  • $_GET['idlab'] is not set Commented Apr 24, 2014 at 1:14
  • That is what I don't get! The example I saw used the exact same thing. I literally tried to copy paste and replace variables but nothing.... Commented Apr 24, 2014 at 1:15
  • I even used the code you gave me yesterday to try and patch things up but nada. Commented Apr 24, 2014 at 1:16
  • Only change is the error: : Undefined index: idlab which is bollocks because when I tried a long winded way to make it work it called the function but instead displayed the information in a mess. Commented Apr 24, 2014 at 1:20
  • 1
    Put print_r($_GET); at the top of the page and let me know what it says. Commented Apr 24, 2014 at 1:27

1 Answer 1

2

You're using $_GET not $_POST. So change:

isset($_POST['lab']) ? $_POST['lab'] : 'Unknown';

to:

isset($_GET['lab']) ? $_GET['lab'] : 'Unknown';
Sign up to request clarification or add additional context in comments.

1 Comment

Worked perfectly, you're a hero to me.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.