Good, I want to pass the data that appear in my table to a form on another page, I am doing it to myself and it does not pull me

0
<form role="form" name="boton" action="../cd/pre.php" method="POST"">

            <table class="table">
                <div class="alert alert-info">
        <h2>Mis Encuestas</h2>
        </div>
                <tr>
                    <th>Codigo</th>
                    <th>Nombre</th> 
                    <th>Fecha</th>
                    <th>Consultar</th>


                </tr>
                <?php
                while ($lista=$rs->fetch_array(MYSQL_BOTH)) { 
                  //$_SESSION['id'] =$lista['idEncusta'];

                      echo '<tr>
                    <td>'.$lista['idEncuesta'].'</td>
                    <td>'.$lista['NomEncuesta'].'</td>
                    <td>'.$lista['fecha'].'</td>

                    <td> <input type="submit" name="boton" value="Ver"> </td>


                </tr>';

                }
                ?>
                <input type="hidden" name="id" value="<?php echo $lista['idEncuesta']; ?>">
                </table>

                     </form>

pre.php

<?php
require("conexion.php");
    $id=$_POST["id"];
//session_start();
 //$id=$_SESSION["id"];

     $alumno = "SELECT * FROM preguntas where(idEncuesta='$id')";
     $rs=$con->query($alumno);
 ?>
    
asked by Luis Navarro Saravia 08.06.2018 в 09:23
source

1 answer

0

Could you add the error that the logs show you? (in case one is shown).

And assuming that the query is done, you could continue with the session management to send the info.

The code in your "pre.php" would be something like this.

<?php 
      session_start();
      require("conexion.php");
      $id = $_REQUEST[id]; //Request the info from index page

       $alumno = "SELECT * FROM preguntas where(idEncuesta='$id')";
      ?>

Remember that to use the sessions after sending the POST, on your destination page you add the $ _ REQUEST [id]; statement without using quotes between the brackets. You can even assign it to a variable in the following way.

for the query to the DB you can also send the direct request something like that

$alumno = "SELECT * FROM preguntas where(idEncuesta='$_REQUEST[id]')";

and it will work properly.

Recommendations to the code, try to use names / ids that reprecenten the functionality of the object. In case the code is not working, it would be useful to add "what does and does not do the code".

So you could 1.- Review the "action" of the form at the moment you are sending the info. 2.- The way to send the info with the "input hidden" using the list directly. You could try changing the way you're assigning the value something like this:

<?php
            while ($lista=$rs->fetch_array(MYSQL_BOTH)) { 
              //$_SESSION['id'] =$lista['idEncusta'];

                  echo '<tr>
                <td>'.$lista['idEncuesta'].'</td>
                <td>'.$lista['NomEncuesta'].'</td>
                <td>'.$lista['fecha'].'</td>

                <td> <input type="submit" name="boton" value="Ver"> </td>


            </tr>';

            }
           echo ('<input type="hidden" name="id" value="'.$lista['idEncuesta'].'">'; ?>

I hope and it serves something. Make sure that the variable of $ list ['idEncuesta'] is properly displayed with an Alert or an Echo in your code. You tell us how it went and how you solved it.

Greetings!

    
answered by 08.06.2018 в 16:42