Problems with receiving variable get [closed]

0

I have this simple error, but I can not tell what I'm doing wrong Undefined index: activity_id

$id = $_GET['id_actividad'];
	 

	$sql = "SELECT * FROM actividad WHERE id_actividad = '$id'";
	$resul1= mysqli_query($conexion,$sql);

and I want to rescue id_activity to apply it in a file editing modal, where you should see the files links to that activity, but since you do not recognize me the id_activity shows me all the files in the Files folder (where I save the files) .

      <div id="updateFiles" class="modal fade" role="dialog">
         <div class="modal-dialog">
            <!-- Modal content-->
            <div class="modal-content">
               <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal">&times;</button>
                  <h4 class="modal-title"></h4>
               </div>
               <div class="modal-body">
                  <table align="center">
                    
                    <input type="text" id="idactividad" hidden="" name="idactividad">
                     <tr>
                        <label>Archivo</label>
                        <input type="file"  multiple="multipleu" id="archivosu" name="archivosu" class="form-control-file"><!-- Este es nuestro campo input File-->
                     </tr>
                     
                     <?php
                      
                    $path = "Files/".$id;
                    if(file_exists($path)){
                    $directorio = opendir($path); //ruta actual
                    
                            while ($archivo = readdir($directorio)) //obtenemos un archivo y luego otro sucesivamente
                            {
                            if (!is_dir($archivo)){
                                
										echo "<div data='".$path."/".$archivo."'><a href='".$path."/".$archivo."' title='Ver Archivo Adjunto'><span class='glyphicon glyphicon-picture'></span></a>";
										echo "$archivo <a href='#' class='delete' title='Ver Archivo Adjunto' ><span class='glyphicon glyphicon-trash' aria-hidden='true'></span></a></div>";
										echo "<img src='files/$id/$archivo' width='300' />";
									}
                                    else
                            {
                            echo $archivo . "<br />";
                            }
                            }
                        }
                     ?>
                     
                   
                     
                  </table>
               </div>
               <div class="modal-footer">
                  <center>
                     <td><button class="btn btn-primary" onclick="editarArchivo()">Enviar Imagenes</button></td>
                  </center>
               </div>
            </div>
         </div>
      </div>

<script>
           function editarArchivo(){

               var idactividad= document.getElementById("idactividad").value;
               var archivosu= document.getElementById("archivosu").value;

               var data = '&idactividad='+idactividad+'&archivosu='+archivosu;

               $.ajax({
               type: 'POST',
               url: 'php/update_file.php',
               data: data,
               beforeSend: function() {
               console.log('enviando datos a la BD...');
               },
               success: function(data) {
               console.log(data);
              location.reload();
               }
               })
               return false;

         };
       
   
       
</script>

That's how it looks

then I get the file editing modal

    
asked by claudia24 05.06.2018 в 07:49
source

2 answers

1

The problem is that you expect to receive it by GET and you are sending it by POST. You have also defined it as idactividad but you collect it as id_actividad.

Change this

$id = $_GET['id_actividad'];

for this

$id = $_POST['idactividad'];
    
answered by 05.06.2018 в 08:02
0

you could also try this way

$id = $_REQUEST['id_actividad'];

With this you could not fail to send variable by post or get ... accept them at 2.

    
answered by 05.06.2018 в 08:10