-4

i recently uninstalled wampser due to some problems with replication and now im working with xampp.

but now i have another problem, when i had wamp i could upload pictures to the database perfectly but know on xampp it keeps giving me this error...

Notice: Undefined index: imagenn in C:\xampp\htdocs\PaginaV2\PHPyJS\Procesoalumno.php on line 12

Notice: Undefined index: imagenn in C:\xampp\htdocs\PaginaV2\PHPyJS\Procesoalumno.php on line 13

this is my html code:

<FORM action="PHPyJS\ProcesoAlumno.php" method="post" style="margin-left:10%"> 
 <p id="titulo">Alta de Alumnos</p>

 <div id="campos11"><p>Nombre(s):</p>
 <input type="text" name="txtnombrealumno" id="txtnombrealumno" style="border-radius:2px; border:1px solid #000"><br>
 <p>Apellido Paterno:</p>
 <input type="text" name="txtapellidopaternoalumno" id="txtapellidopaternoalumno" style="border-radius:2px; border:1px solid #000"><br>
 <p>Apellido Materno:</p>
 <input type="text" name="txtapellidomaternoalumno" id="txtapellidomaternoalumno" style="border-radius:2px; border:1px solid #000"><br>
 <p>Carrera:</p>
 <input type="text" name="txtcarrera" id="txtcarrera" style="border-radius:2px; border:1px solid #000"><br>
 <p>Correo Electronico:</p>
 <input type="text" name="txtcorreoelectronico" id="txtcorreoelectronicoalumno" style="border-radius:2px; border:1px solid #000"><br>
 <p>Contraseña:</p>
 <input type="text" name="txtcontra" id="txtcontra2" style="border-radius:2px; border:1px solid #000"><br></div>

 <div id="campos12"><div id="im2"></div>
 <input type="file" name="imagenn" id="imagenn" style="height:20px; width:135px"></div>
  <input type="submit" value="Agregar" id="botonagr">
     </FORM> 

and this is my php code that executes un the sumbit button:

$nomreimg = $_FILES["imagenn"]['name'];
$archivo = $_FILES["imagenn"]['tmp_name'];
$ruta= "C:\xampp\htdocs\PaginaV2\Imagen";

$ruta = $ruta."/".$nomreimg;
move_uploaded_file($archivo,$ruta);

//declaracion de variables para ingresar datos
$nombre = $_POST['txtnombrealumno'];
$apellidopaterno = $_POST['txtapellidopaternoalumno'];
$apellidomaterno = $_POST['txtapellidomaternoalumno'];
$correoelectronico = $_POST['txtcorreoelectronico'];
$carrera = $_POST['txtcarrera'];
$contra = $_POST['txtcontra'];




$insertar =("insert into ALUMNOS (ID_ALUMNO,AL_FOTOGRAFIA,AL_NOMBRE,AL_APATERNO, AL_AMATERNO, AL_CORREO, AL_CARRERA, AL_ID_ADMIN, AL_PASS , AL_ID_GRUPO) Values 
(null,'$nomreimg', '$nombre' , '$apellidopaterno', '$apellidomaterno', '$correoelectronico','$carrera','1', '$contra','1');");

$resultado = mysqli_query($conexion,$insertar);

i dont know why it is saying undefined if i have it in the html code for the file container (where i select the picture) and the use the same id or name on the php to get that picture...

B. Desai
  • 16,414
  • 5
  • 26
  • 47

2 Answers2

1

You need to use :

<form action="PHPyJS\ProcesoAlumno.php" method="post" style="margin-left:10%" enctype="multipart/form-data">

You missed the attribute :

 enctype="multipart/form-data"

More informations : https://www.w3schools.com/php/php_file_upload.asp

Vincent Decaux
  • 9,857
  • 6
  • 56
  • 84
1

For uploading file you must have to set enctype="multipart/form-data" in you form. so change your form to

<FORM enctype="multipart/form-data" action="PHPyJS\ProcesoAlumno.php" method="post" style="margin-left:10%"> 
B. Desai
  • 16,414
  • 5
  • 26
  • 47