No llevo mucho con php y estoy haciendo un programilla en el que tengo que crear un profesor, y ese profesor tiene que introducir sus titulaciones (que pueden ser una o varias). Entonces tengo un interfaz para introducir el profesor:
Código:
Y con el botón añadir titulación me voy a otro interfaz donde se introducirían las titulaciones:<? session_start(); ?> <html> <head> <title>Crear un profesor</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <? include("conexion.php"); $sql = "select * from profesores where login = '".$login."'"; $result = mysql_query($sql, $GLOBALS["miConexion"]) or die(mysql_error()); $fila= mysql_fetch_assoc($result); $sql1 = "select * from titulaciones where DNIProfesor = '".$fila['DNI']."'"; $result1 = mysql_query($sql1, $GLOBALS["miConexion"]) or die(mysql_error()); $nFilas=mysql_num_rows($result1); echo '<form name="f" method = "POST" action ="guardarNuevoProfesor.php"> <h2>Datos de un nuevo profesor</h2> <div style="margin-left: 3%; width=200px;"> DNI: <input name="cDNI" type="text"> <br><br> Nombre: <input name="cNombre" type="text"">    Primer apellido: <input name="cApellido1" type="text">    Segundo apellido: <input name="cApellido2" type="text"> <br><br> Dirección: <input name="cDireccion" type="text" size="40">    Teléfono: <input name="cTelefono" type="text"> <br><br>'; echo '<fieldset size="10"><p><legend>Dedicación</legend></p><p></p><label> <input type="radio" name="cDedicacion" value="valorTotal">Total</label>  <label> <input type="radio" name="cDedicacion" value="valorParcial">Parcial</label><br> </fieldset>'; echo '<br><br> Otras actividades: <br> <textarea name="cOtrasActividades" cols="40" rows="4"></textarea>'; echo '<br><br> <input name="cDirector" type="checkbox" value="valorDirector"> Director <input name="cSubdirector" type="checkbox" value="valorSubdirector"> Subdirector <input name="cTutor" type="checkbox" value="valorTutor"> Tutor <input name="cJefeSeccion" type="checkbox" value="valorJefeSeccion"> Jefe sección <input name="cOrientador" type="checkbox" value="valorOrientador"> Orientador <br><br> <center> <input name="botonGuardar" type="submit" value="Guardar"> <a href="anadirTitulacion.php"><input name="botonAnadirTitulacion" align="right" type="button" value="Añadir titulación"></a> <br><br> </center> </form>'; ?> </body> </html>
Código:
Estos dos scripts por separado me funcionan muy bien, pero el problema viene en que la manera natural de rellenar este formulario es rellenar el profesor primero, las titulaciones después y ya el tercer paso sería guardar el profesor con sus titulaciones, pues bien, relleno al profesor, me voy a las titulaciones y relleno las titulaciones y cuando vuelvo a la página del profesor me carga otra vez la página y los datos que tenía rellenos ya no están. Y no sé cómo podría almacenarlos para actualizar el formulario cuando el usuario venga de meter sus titulaciones, en la sesión???? Si puediérais ayudarme.<? session_start(); ?> <html> <head> <title>Dar de alta una titulación de un profesor</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript"> <!-- num=0; function crear(obj) { num++; fi = document.getElementById('fiel'); // 1 //fi.insertBefore(contenedor,obj); // 2 contenedor = document.createElement('div'); // 2 contenedor.id = 'div'+num; // 3 fi.appendChild(contenedor); // 4 ele = document.createElement('input'); // 5 ele.type = 'text'; // 6 ele.name = 'text'+num; // 6 ele.size = '40'; contenedor.appendChild(ele); // 7 ele = document.createElement('input'); // 5 ele.type = 'button'; // 6 ele.value = 'Borrar'; // 8 ele.name = 'div'+num; // 8 ele.onclick = function () {borrar(this.name)} // 9 contenedor.appendChild(ele); // 7 } function borrar(obj) { fi = document.getElementById('fiel'); // 1 fi.removeChild(document.getElementById(obj)); // 10 } function enviar(){ document.form1.submit(); } --> </script> </head> <body> <? include("conexion.php"); // Recojo las titulaciones que lleva hasta el momento introducidas el usuario $sql = "select * from titulaciones where DNIProfesor = '".$fila['DNI']."'"; $result = mysql_query($sql, $GLOBALS["miConexion"]) or die(mysql_error()); $nFilas=mysql_num_rows($result); echo '<form name="f" method = "POST" action ="guardarTitulacion.php" OnSubmit="return validar(this)"> <div style="margin-left: 3%; width=200px;"> '; echo'<h2>Nombre de la nueva titulación</h2>'; echo ' <fieldset id="fiel"> <input type="button" value="Añadir titulación" onclick="crear(this)"> </fieldset>'; if ($nFilas>0){ echo'<h2>Titulaciones introducidas para este profesor hasta el momento</h2>'; while($fila= mysql_fetch_assoc($result)){ echo'<br><br>    <input name="'.$fila['nombreTitulacion'].'" type="text" readonly="true" size="40" value="'.$fila['nombreTitulacion'].'">'; } }else{ echo'<h3>No hay titulaciones introducidas para este profesor hasta el momento</h3>'; } echo '<br><br>'; echo' <center> <input type="submit" value="Guardar" onclick="enviar(this)">'; echo' <a href="crearProfesor.php"><input name="botonVolver" align="right" type="button" value="Volver"></a> <br><br> </center> </form>'; ?> </body> </html>
Gracias.