Form html will not let me upload information to bdd in phoMyAdmin

0

I am working on an html form to send me data through the POST method to a file registerAcursos.php but it will not let me enter the data I get with the first sql, I get an error that could not send the data.

and look for error comparing with other files to verify the same and can not find anything.

                <form class="form-horizontal form-label-left"  action="registrarAcursos.php" method="POST">
                
                <h4>Busca el Alumno</h4>
                <p class="font-gray-dark">
                  Seleciona el alumno que quieres registrar al : <?php echo $_SESSION['nombre_c'] ?> .
                </p>
                <div class="col-md-8 center-margin">
                    <div class="form-group">
                      <label>Ingresa el Nombre De Usuario Del alumno que quieres ingresar</label>
                      <input name="usuario" type="text" class="form-control" placeholder="Enter email">
                    </div>
                </div>     
        <center>
          <button type="submit" class="btn btn-primary" style="margin-right: 5px;"><i class="fa fa-download"></i> Agregar Alumno</button>
        </center>


                  <?php
                $ID = $_SESSION['id_c'];

$mensaje = $_GET['msj'];
if ($mensaje == "si"){
    header('Location:aggAlumnos.php') ;
} 
if($mensaje == "no"){
    echo "Usuario incorrecto";
}
if ($mensaje == "ya"){
    
    
    echo "El usuario no existe";

}
?>
                </form>
 and this is the php code

<?php

include("conexion.php");

$usuario = $_POST['usuario'];

$sql="SELECT USUARIO FROM USUARIOS WHERE USUARIO='$usuario'";

$result= $conn->query($sql);

if($result->num_rows>0){

	    $IDUSUARIO = $row['IDUSUARIO'];
        $NOMBRE = $row['NOMBRE'];
		$IDC = $_SESSION['id_c'];
	    $NOMBRE_C = $_SESSION['nombre_c'];
	
	      
	$sql2 = "INSERT INTO REGISTRO(ID_ALUMNO,NOMBRE_ALUMNO,ID_CURSO,NOMBRE_CURSO)
	         VALUES('$IDUSUARIO','$NOMBRE','$IDC','$NOMBRE_C')";

	$result2=$conn->query($sql2);

	if($result2 === TRUE){
        header('Location:aggAlumnos.php?msj=si') ;
	}else{
		 header('Location:aggAlumnos.php?msj=no') ;
	}

}else{

header('Location:aggAlumnos.php?msj=ya') ;

}



?>
    
asked by Leo Tutorials 02.08.2018 в 06:49
source

1 answer

0

The thing is that you take a variable $row out of nothing. You should use some method to traverse the results (foreach or while).

Here's an example:

<?php

include("conexion.php");

$usuario = $_POST['usuario'];

$sql="SELECT USUARIO FROM USUARIOS WHERE USUARIO='$usuario'";

$result= $conn->query($sql);

if($result->num_rows>0){
    while ($row=mysqli_fetch_row($result)){
	    $IDUSUARIO = $row['IDUSUARIO'];
            $NOMBRE = $row['NOMBRE'];
            $IDC = $_SESSION['id_c'];
	    $NOMBRE_C = $_SESSION['nombre_c'];
	}
	      
	$sql2 = "INSERT INTO REGISTRO(ID_ALUMNO,NOMBRE_ALUMNO,ID_CURSO,NOMBRE_CURSO)
	         VALUES('$IDUSUARIO','$NOMBRE','$IDC','$NOMBRE_C')";

	$result2=$conn->query($sql2);

	if($result2 === TRUE){
        header('Location:aggAlumnos.php?msj=si') ;
	}else{
		 header('Location:aggAlumnos.php?msj=no') ;
	}

}else{

header('Location:aggAlumnos.php?msj=ya') ;

}



?>
    
answered by 02.08.2018 / 11:05
source