• Martes 30 de Abril de 2024, 04:26

Autor Tema:  Formulario Php  (Leído 1313 veces)

Adriana Olvera

  • Nuevo Miembro
  • *
  • Mensajes: 21
    • Ver Perfil
Formulario Php
« en: Jueves 5 de Julio de 2007, 20:58 »
0
Hola, pues yo tengo un pequeño problema con mi código, debe guardar y modificar registros pero no lo hace, ya revise varias veces y no encuentro el érror, tal vez sea una insignificancia pero no la veo y necesito terminar eso para poder continuar con el diseño de mi página, espero que me puedan ayudar, los códigos que tengo son:

 :) formularioexamen.php
<?php
include ("conexion.php");

if ($_GET[accion]=="alta")
    {
    // Es un alta
    $accion='alta';
    $id_materia="";
    $no_preguntas="";
    $parcial="";
    $tipo="";
    $id_estado="";
    $num_empleado="";
    $fecha="";
    $id_grupo="";
    }
else
    {
    // Es una modificacion
    $rs = mysql_query ("select * from examen where id_examen='$_GET[id_examen]'") or die (mysql_error());
    $reg=mysql_fetch_array($rs);
    $id_materia = $reg[id_materia];
    $no_preguntas = $reg[no_preguntas];
    $parcial = $reg[parcial];
    $tipo = $reg[tipo];
    $id_estado = $reg[id_estado];
    $num_empleado = $reg[num_empleado];
    $fecha = $reg[fecha];
    $id_grupo = $reg[id_grupo];
    $accion="cambio";
    }
?>
<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script><title>Registros</title>
 

<form method='get' name="form1" id="form1" <?php echo ("action='examenaccion.php?id_examen=$id_examen&accion=cambio'"); ?>>
    <input type='hidden' name='accion'>
    GENERAR EXAMEN <br /><br />
  <table border='1'>
  <tr>
  <td>id_materia:</td>
  <td>
    <select name='id_materia' class='conborde'>
     <option value='0' <?php if ($reg[id_materia]=='0') {echo ("selected");} ?>>--Elegir       Materia--</option>
      <option value='1' <?php if ($reg[id_materia]=='1') {echo ("selected");} ?>>Matemáticas 1</option>
      <option value='2' <?php if ($reg[id_materia]=='2') {echo ("selected");} ?>>Informática 1</option>
      <option value='3' <?php if ($reg[id_materia]=='3') {echo ("selected");} ?>>Administración</option>
      <option value='4' <?php if ($reg[id_materia]=='4') {echo ("selected");} ?>>Contabilidad</option>
      <option value='5' <?php if ($reg[id_materia]=='5') {echo ("selected");} ?>>Idioma       Extranjero 1</option>
      <option value='6' <?php if ($reg[id_materia]=='6') {echo ("selected");} ?>>Expresión Oral       y Escrita 1</option>
      <option value='7' <?php if ($reg[id_materia]=='7') {echo ("selected");} ?>>Formación       Sociocultural 1</option>
    </select>   </td>
  </tr>
  <tr>
  <td>no_preguntas:</td>
  <td><input name='no_preguntas' type='text' onfinish="MM_validateForm('no_preguntas','','RisNum'); return document.MM_returnValue" <?php echo "value='$reg[no_preguntas]'"; ?>></td></tr>
<tr>
  <td>Parcial:</td>
  <td><select name='parcial' class='conborde'>
  <option value='Primero' <?php if ($reg[parcial]=='Primero'){print ("selected");} ?>> Primero</option>
  <option value='Segundo' <?php if ($reg[parcial]=='Segundo'){print ("selected");} ?>> Segundo</option>
  <option value='Tercero' <?php if ($reg[parcial]=='Tercero'){print ("selected");} ?>> Tercero</option>
  </select>  </td>
</tr>
<tr>
  <td>tipo:</td>
  <td>
  <select name='tipo' class='conborde'>
  <option value='Ord' <?php if ($reg[tipo]=="Ord") {print ("selected");} ?>> Ordinario</option>
  <option value='Rem' <?php if ($reg[tipo]=="Rem") {print ("selected");} ?>> Remedial</option>
  <option value='Extra' <?php if ($reg[tipo]=="Extra") {print ("selected");} ?>> Extraordinario</option>
  <option value='Ultmat' <?php if ($reg[tipo]=="Ultimat") {print ("selected");} ?>> Última Materia</option></select>  </td>
</tr>
<tr>
  <td>id_estado:</td>
  <td><select name='id_estado' class='conborde'>
  <option value='1' <?php if ($reg[id_estado]=="1") {print ("selected");} ?>>Activo</option>
  <option value='2' <?php if ($reg[id_estado]=="2") {print ("selected");} ?>>Inactivo</option>
  <option value='3' <?php if ($reg[id_estado]=="3") {print ("selected");} ?>>Cancelado</option></select>  </td>
</tr>
<tr>
  <td>num_empleado: </td>
  <td><input name='num_empleado' type='text' onfinish="MM_validateForm('num_empleado','','RisNum');return document.MM_returnValue" <?php echo "value='$reg[num_empleado]'"; ?>></td>
</tr>
<tr>
  <td>fecha:</td>
   <td>
<?php
  $dia = substr($reg[fecha],8,2);
  $mes = substr($reg[fecha],5,2);
  $anio = substr($reg[fecha],0,4);
  echo "fecha - $reg[fecha]<br>dia - $dia<br>mes - $mes<br>año - $anio<br>";
  ?>  
Día: <select name='dia' size='1' class='conborde'>
   <?php
   for ($co=1;$co<=31;$co++){
      echo ("<option value='$co'"); if($co==$dia){echo ("selected");} echo ">$co</option>";
   }
   ?>
   </select>
   
 Mes: <select name='mes' class='conborde'>
  <option value='01' <?php if ($mes=="01"){echo ("selected");} ?>> Ene </option>
  <option value='02' <?php if ($mes=="02"){echo ("selected");} ?>> Feb </option>
  <option value='03' <?php if ($mes=="03"){echo ("selected");} ?>> Mar </option>
  <option value='04' <?php if ($mes=="04"){echo ("selected");} ?>> Abr </option>
  <option value='05' <?php if ($mes=="05"){echo ("selected");} ?>> May </option>
  <option value='06' <?php if ($mes=="06"){echo ("selected");} ?>> Jun </option>
  <option value='07' <?php if ($mes=="07"){echo ("selected");} ?>> Jul </option>
  <option value='08' <?php if ($mes=="08"){echo ("selected");} ?>> Ago </option>
  <option value='09' <?php if ($mes=="09"){echo ("selected");} ?>> Sep </option>
  <option value='10' <?php if ($mes=="10"){echo ("selected");} ?>> Oct </option>
  <option value='11' <?php if ($mes=="11"){echo ("selected");} ?>> Nov </option>
  <option value='12' <?php if ($mes=="12"){echo ("selected");} ?>> Dic </option>
 </select>
 Año: <select name='anio' class='conborde'>
 <option value='2007' <?php if ($anio=="2007") {echo ("selected");} ?>> 2007 </option>
 <option value='2008' <?php if ($anio=="2008") {echo ("selected");} ?>> 2008 </option>
 <option value='2009' <?php if ($anio=="2009") {echo ("selected");} ?>> 2009 </option>
 <option value='2010' <?php if ($anio=="2010") {echo ("selected");} ?>> 2010 </option>
 <option value='2011' <?php if ($anio=="2011") {echo ("selected");} ?>> 2011 </option>
 <option value='2012' <?php if ($anio=="2012") {echo ("selected");} ?>> 2012 </option>
 <option value='2013' <?php if ($anio=="2013") {echo ("selected");} ?>> 2013 </option>
 <option value='2014' <?php if ($anio=="2014") {echo ("selected");} ?>> 2014 </option>
 <option value='2015' <?php if ($anio=="2015") {echo ("selected");} ?>> 2015 </option>
 <option value='2016' <?php if ($anio=="2016") {echo ("selected");} ?>> 2016 </option>
 <option value='2017' <?php if ($anio=="2017") {echo ("selected");} ?>> 2017 </option>
 <option value='2018' <?php if ($anio=="2018") {echo ("selected");} ?>> 2018 </option>
 <option value='2019' <?php if ($anio=="2019") {echo ("selected");} ?>> 2019 </option>
 <option value='2020' <?php if ($anio=="2020") {echo ("selected");} ?>> 2020 </option>
 <option value='2021' <?php if ($anio=="2021") {echo ("selected");} ?>> 2021 </option>
</select></tr>
<tr>
<td>id_grupo:</td>
<td><select name='id_grupo' class='conborde'>
  <option value="0">--Select grupo--</option>
  <option value='1' <?php if ($reg[id_grupo]=="1") {print ("selected");} ?>>T72</option>
  <option value='2' <?php if ($reg[id_grupo]=="2") {print ("selected");} ?>>T73</option>
  <option value='3' <?php if ($reg[id_grupo]=="3") {print ("selected");} ?>>T74</option>
  <option value='4' <?php if ($reg[id_grupo]=="4") {print ("selected");} ?>>T76</option>
  <option value='5' <?php if ($reg[id_grupo]=="5") {print ("selected");} ?>>T77</option>
  <option value='6' <?php if ($reg[id_grupo]=="6") {print ("selected");} ?>>T79</option>
  <option value='7' <?php if ($reg[id_grupo]=="7") {print ("selected");} ?>>T80</option>
  <option value='8' <?php if ($reg[id_grupo]=="8") {print ("selected");} ?>>T81</option>
  <option value='9' <?php if ($reg[id_grupo]=="9") {print ("selected");} ?>>T82</option>
  <option value='10' <?php if ($reg[id_grupo]=="10") {print ("selected");} ?>>T83</option>
  <option value='11' <?php if ($reg[id_grupo]=="11") {print ("selected");} ?>>T84</option>
  <option value='12' <?php if ($reg[id_grupo]=="12") {print ("selected");} ?>>T85</option>
  <option value='13' <?php if ($reg[id_grupo]=="13") {print ("selected");} ?>>T86</option>
  <option value='14' <?php if ($reg[id_grupo]=="14") {print ("selected");} ?>>T87</option>
  <option value='15' <?php if ($reg[id_grupo]=="15") {print ("selected");} ?>>T88</option>
  </select>  </td>
</tr>
<tr>
<td colspan="2">
<input type="reset" name="Restablecer" id="Restablecer" value="Restablecer">
<input name="Enviar" type="submit" id="Enviar" value="Enviar"></td>
</tr>
</table>

<?php
mysql_close();
?>
</form>
</body>
</html>

 :) examenaccion.php
<?php
include ("conexion.php");

switch ($_GET[accion])
 {
  case "alta":
  $fecha=$_POST[anio].'/'.$_POST[mes].'/'.$_POST[dia];
  mysql_query ("insert into examen values ('', '$_GET[id_materia]', '$_GET[no_preguntas]', '$_GET[parcial]', '$_GET[tipo]', '$_GET[id_estado]', '$_GET[num_empleado]', '$_GET[fecha]',  '$_GET[id_grupo]')") or die (mysql_error());
  break;
 
  case "cambio":
  mysql_query ("update examen set id_materia='$_POST[id_materia]' where  id_examen='$_GET[id_examen]'") or die (mysql_error());
  mysql_query ("update examen set no_preguntas='$_POST[no_preguntas]' where  id_examen='$_GET[id_examen]'") or die (mysql_error());
  mysql_query ("update examen set parcial='$_POST[parcial]' where id_examen='$_GET[id_examen]'")  or die (mysql_error());  
  mysql_query ("update examen set tipo='$_POST[tipo]' where id_examen='$_GET[id_examen]'") or  die (mysql_error());
  mysql_query ("update examen set id_estado='$_POST[id_estado]' where  id_examen='$_GET[id_examen]'") or die (mysql_error());
  mysql_query ("update examen set num_empleado='$_POST[num_empleado]' where  id_examen='$_GET[id_examen]'") or die (mysql_error());
  mysql_query ("update examen set id_grupo='$_POST[id_grupo]' where  id_examen='$_GET[id_examen]'") or die (mysql_error());
  mysql_query ("update examen set fecha='$_POST[fecha]' where id_examen='$_GET[id_examen]'") or  die (mysql_error());
  break;
 
  case "borrar":
  mysql_query ("delete from examen where id_examen='$_GET[id_examen]'") or die (mysql_error());
  break;
 }
 mysql_close();
 header ("location:examena.php");
?>
<title>Acciones</title>
</body>
</html>

 :) examena.php
<?php  
include ("conexion.php");
$rs=mysql_query('select * from examen') or die (mysql_error());

print ("<a href=formularioexamen.php>Crear Examen</a> <a href=bienvenida.html>Cerrar Sesión</a><br><br><table border=1>
<tr><td>id_examen</td><td>id_materia</td><td>no_preguntas</td><td>parcial</td><td>tipo</td><td>id_estado</td><td>num_empleado</td><td>fecha</td><td>id_grupo</td><td colspan=2><center>Acciones</td></tr>");


 while ($reg=mysql_fetch_array ($rs))
    {
     $id_examen=$reg['id_examen'];
    $id_materia = $reg['id_materia'];
    $no_preguntas = $reg['no_preguntas'];
    $parcial = $reg['parcial'];
    $tipo = $reg['tipo'];
    $id_estado = $reg['id_estado'];
    $num_empleado = $reg['num_empleado'];
    $fecha= $reg['fecha'];
    $id_grupo = $reg['id_grupo'];
   
   print ("<tr><td>$id_examen</td><td>$id_materia</td><td>$no_preguntas</td><td>$parcial</td>    <td>$tipo</td><td>$id_estado</td><td>$num_empleado</td><td>$fecha</td><td>$id_grupo</td>
   <td><a href='formularioexamen.php?id_examen=$id_examen&accion=cambio'>modificar</a></td>
   <td><a href='examenaccion.php?id_examen=$id_examen&accion=borrar'>borrar</a></td></tr>");
   }
   print ("</table><br>");
   ?>
<?php   
mysql_close();
?>
<html>
<body>
<title>Tabla de Examenes</title>
</body>
</html>
No todo lo que es oro brilla, remedio chino e infalible.

LeGatoRojo

  • Miembro HIPER activo
  • ****
  • Mensajes: 552
  • Nacionalidad: mx
    • Ver Perfil
    • LeGatoRojo
Re: Formulario Php
« Respuesta #1 en: Jueves 5 de Julio de 2007, 21:03 »
0
Pues si esta algo largo el código, podrías mandar el error, ya que veo que mandas mysql_error, si no para buscar por otro lado.
Un día desperte y en lugar de dientes tenía colmillos, en lugar de manos, tenía garras; pero lo más impactante fue el color escarlata de mi pelaje.

Adriana Olvera

  • Nuevo Miembro
  • *
  • Mensajes: 21
    • Ver Perfil
Re: Formulario Php
« Respuesta #2 en: Jueves 5 de Julio de 2007, 21:20 »
0
Hola, de hecho la página no me marca ningún error, pero cuando yo quiero guardar un registro no me lo guarda ni modifica tampoco, la dirección de la página es la siguiente: desarrollo.uteq.edu.mx/examenes/formularioexamen.php ahí muestra la tabla que tengo en mysql y tiene una liga para crear, de ahí manda a un formulario y debería guardar los datos en la tabla al dar enviar pero no lo hace.
No todo lo que es oro brilla, remedio chino e infalible.

LeGatoRojo

  • Miembro HIPER activo
  • ****
  • Mensajes: 552
  • Nacionalidad: mx
    • Ver Perfil
    • LeGatoRojo
Re: Formulario Php
« Respuesta #3 en: Jueves 5 de Julio de 2007, 21:36 »
0
Código: Text
  1. &#60;input type='hidden' name='accion'&#62;
  2.  
en esta seccion del codigo te falta el value, por eso no entra en ningun caso del switch en examenacion.php
Un día desperte y en lugar de dientes tenía colmillos, en lugar de manos, tenía garras; pero lo más impactante fue el color escarlata de mi pelaje.

Adriana Olvera

  • Nuevo Miembro
  • *
  • Mensajes: 21
    • Ver Perfil
Re: Formulario Php
« Respuesta #4 en: Jueves 5 de Julio de 2007, 21:56 »
0
Gracias por ayudarme, pero ya modifique eso y no era, le voy a seguir moviendo haber si le encuentro algo, muchas gracias y hasta luego. :hola:
No todo lo que es oro brilla, remedio chino e infalible.