Foros del Web » Programando para Internet » PHP »

get y post en un mismo formulario

Estas en el tema de get y post en un mismo formulario en el foro de PHP en Foros del Web. Hola Tengo un formulario donde doy de alta a alumnos como veran tengo codigo PHP que me llama unos datos de una BD el Formulario ...
  #1 (permalink)  
Antiguo 23/03/2010, 00:42
 
Fecha de Ingreso: noviembre-2009
Mensajes: 23
Antigüedad: 14 años, 5 meses
Puntos: 0
Exclamación get y post en un mismo formulario

Hola
Tengo un formulario donde doy de alta a alumnos como veran tengo codigo PHP que me llama unos datos de una BD el Formulario es este:

Código HTML:
<FORM enctype="multipart/form-data" method="post" action="">
  <div id="Layer19">
  <table width="584">
  <tr>
    <td height="43" colspan="3"><div align="center" class="Estilo13">Alta de alumnos </div></td>
    </tr>
  <tr>
    <td height="33" class="Estilo12"><div align="right">Id Del Alumno </div></td>
    <td colspan="2"><label>
      <input name="id" type="text" id="id" />
    </label></td>
  </tr>
  <tr>
    <td width="240" height="33" class="Estilo12"><div align="right">Nombre:</div></td>
    <td colspan="2"><label>
      <input name="nombre" type="text" id="nombre" value="[PHP]<? echo"$res[0]";?>[/PHP]"/>
    </label></td>
    </tr>
  <tr>
    <td height="32" class="Estilo12"><div align="right">Apellido Paterno: </div></td>
    <td colspan="2"><label>
      <input name="apPaterno" type="text" id="apPaterno" value="[PHP]<? echo"$res[1]";?>[/PHP]" />
    </label></td>
    </tr>
  <tr>
    <td height="34" class="Estilo12"><div align="right">Apellido Materno: </div></td>
    <td colspan="2"><label>
    <input name="apMaterno" type="text" id="apMaterno" value="[PHP]<? echo"$res[2]";?>[/PHP]" />
    </label></td>
    </tr>
  <tr>
    <td height="33" class="Estilo12"><div align="right">Edad:</div></td>
    <td colspan="2"><label>
      <input name="edad" type="text" id="edad" value="[PHP]<? echo"$res[3]";?>[/PHP]" size="3" maxlength="2" />
    </label></td>
    </tr>
  <tr>
    <td height="34" class="Estilo12"><div align="right">Tutor:</div></td>
    <td colspan="2"><label>
      <input name="tutor" type="text" id="tutor" value="[PHP]<? echo"$res[4]";?>[/PHP]" />
    </label></td>
    </tr>
  <tr>
    <td height="32" class="Estilo12"><div align="right">Direcci&oacute;n:</div></td>
    <td colspan="2"><label>
      <input name="direccion" type="text" id="direccion" value="[PHP]<? echo"$res[5]";?>"[/PHP] />
    </label></td>
    </tr>
  <tr>
    <td height="33" class="Estilo12"><div align="right">Telefono:</div></td>
    <td colspan="2"><label>
      <input name="telefono" type="text" id="telefono" value="[PHP]<? echo"$res[6]";?>[/PHP]" />
    </label></td>
    </tr>
  <tr>
    <td height="34" class="Estilo12"><div align="right">Correo:</div></td>
    <td colspan="2"><label>
      <input name="correo" type="text" id="correo" value="[PHP]<? echo"$res[7]";?>[/PHP]"/>
    </label></td>
    </tr>
  <tr>
    <td height="33" class="Estilo12"><div align="right">Inscripci&oacute;n:</div></td>
    <td colspan="2"><label>
      <input name="inscripcion" type="text" id="inscripcion" value="[PHP]<? echo"$res[8]";?>[/PHP]"/>
    </label></td>
    </tr>
  <tr>
    <td height="29" class="Estilo12"><div align="right">Fecha de Inscripci&oacute;n: </div></td>
    <td colspan="2"><label>
    </label><input name="fechaAlta" type="text" id="fechaAlta" value="[PHP]<? echo"$res[9]";?>[/PHP]" size="10" readonly="readonly"/>
        <img src="images/img.png" id="selector" style="cursor: pointer; border: 1px solid red;" title="Selector de Fecha" onmouseover="this.style.background='red';" onmouseout="this.style.background=''" />
        
      <script type="text/javascript">
    Calendar.setup({
        inputField     :    "fechaAlta",     // id of the input field
        ifFormat       :    "%Y-%m-%d",      // format of the input field
        button         :    "selector",  // trigger for the calendar (button ID)
        align          :    "right",           // alignment (defaults to "Bl")
        singleClick    :    true
    });
        </script></label></td>
    </tr>
  <tr>
    <td class="Estilo12"><div align="right">Fotografia</div></td>
    <td colspan="2"><label>
	<input name="archivo" id="archivo" type="file" size="30"/>
	</label></td>
  </tr>
  <tr>
    <td class="Estilo12"><div align="right">Primera Clase </div></td>
    <td colspan="2">[PHP]<?php
include('conexion.php');
$sQuery = mysql_query("Select id_clase, materia from clase"); 

  echo '<select name="clase1" id="clase1" onchange="test()">';
  echo '<option value="0">Elige</option>';
  ?>
<?php
while($row = mysql_fetch_array($sQuery))
   echo '<option value="'.$row['id_clase'].'">'.$row['materia'].'</option>'; 
  ?>[/PHP]</td>
  </tr>
  <tr>
    <td class="Estilo12"><div align="right">Segunda Clase </div></td>
    <td colspan="2">[PHP]<?php
include('conexion.php');
$sQuery = mysql_query("Select id_clase, materia from clase"); 

  echo '<select name="clase2" id="clase2" onchange="test()">';
  echo '<option value="0">Elige</option>';
  ?>
<?php
while($row = mysql_fetch_array($sQuery))
   echo '<option value="'.$row['id_clase'].'">'.$row['materia'].'</option>'; 
?>[/PHP]</td>
  </tr>
  <tr>
    <td class="Estilo12"><div align="right">Tercer Clase </div></td>
    <td colspan="2">[PHP]<?php
include('conexion.php');
$sQuery = mysql_query("Select id_clase, materia from clase"); 

  echo '<select name="clase3" id="clase3" onchange="test()">';
  echo '<option value="0">Elige</option>';
  ?>
<?php
while($row = mysql_fetch_array($sQuery))
   echo '<option value="'.$row['id_clase'].'">'.$row['materia'].'</option>'; 
?>[/PHP]</td>
  </tr>
  <tr>
    <td height="23" colspan="3"><div align="center" class="Estilo14">Rellene Los Siguientes Campos Si El Alumno Adquiere Calzado </div></td>
    </tr>
  <tr>
    <td height="34" class="Estilo12"><div align="right">Zapato:</div></td>
    <td colspan="2"><label>
      <input name="zapato" type="text" id="zapato" />
    </label></td>
    </tr>
  <tr>
    <td class="Estilo12"><div align="right">Talla:</div></td>
    <td colspan="2"><label>
      <input name="talla" type="text" id="talla" />
    </label></td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    <td colspan="2">&nbsp;</td>
    </tr>
  <tr>
    <td><label></label></td>
    <td width="159"><label>
    <div align="center">
      <input name="submit" type="submit" id="submit" value="Guardar" />
    </div>
    </label></td>
    <td width="169"><label></label></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td colspan="2"><label><input name="imp" type="submit" id="imp" value="IMPRIMIR" /></label></td>
    </tr>
</table>
  </div>

</form> 
El problema es que quiero editar los datos de mi BD pero no se puede al oprimir un boton me imprime los datos en los textfield pero al cambiarlos y darle al boton Enviar no lo guarda si le pongo metodo POST al form Si me guarda pero no me muestra nada, si le pongo GET si me muestra pero no me guarda nada .

Mi codigo de guardar es:

Código PHP:
<?php
if(isset($_POST['submit']))
{
if (empty(
$_FILES['archivo']['name'])){
echo
'<script>window.location="altaalumno.php?proceso=falta_indicar_fichero"</script>';
}

$servidor'localhost';
$usuario='root';
$pass='1234';
$bd='musica';
$conexion mysql_connect($servidor,$usuario,$pass) or die("No se pudo realizar la conexion con el servidor.");
mysql_select_db($bd,$conexion) or die("No se puede seleccionar BD");

$binario_nombre_temporal=$_FILES['archivo']['tmp_name'] ;

$binario_contenido addslashes(fread(fopen($binario_nombre_temporal"rb"), filesize($binario_nombre_temporal)));

$binario_id=$_POST['id'];
$binario_nombre=$_FILES['archivo']['name'];
$binario_peso=$_FILES['archivo']['size'];
$binario_tipo=$_FILES['archivo']['type'];

   {include(
'conexion.php');
        
$sql="INSERT INTO alumnos (nombre,apPaterno,apMaterno,edad,tutor,direccion,telefono,correo,zapato,talla,inscripcion,fechaAlta,clase1,clase2,clase3,id_alumnos) VALUES('$_POST[nombre]','$_POST[apPaterno]','$_POST[apMaterno]','$_POST[edad]','$_POST[tutor]','$_POST[direccion]','$_POST[telefono]','$_POST[correo]','$_POST[zapato]','$_POST[talla]','$_POST[inscripcion]','$_POST[fechaAlta]','$_POST[clase1]','$_POST[clase2]','$_POST[clase3]','$_POST[id]')";                                                                                                                                                                                    
        
$resultado=mysql_query($sql,$con);
        if(
$resultado)
        {
         }
       
mysql_close($con);    
       }
$consulta_insertar "INSERT INTO archivos (id, archivo_binario, archivo_nombre, archivo_peso, archivo_tipo) VALUES ('$binario_id', '$binario_contenido', '$binario_nombre', '$binario_peso', '$binario_tipo')";
mysql_query($consulta_insertar,$conexion) or die("No se pudo insertar los datos en la base de datos.");
echo
'<script>window.location="altaalumno.php"</script>';

}
?>
El codigo para obtener los datos es:

Código PHP:
<?php
if(isset($_GET['imp']))
{
//if($_POST['id']!= "")
//{
include ("conectar.php");
$link=conectarse2();

$sql=mysql_query("SELECT nombre,apPaterno,apMaterno,edad,tutor,direccion,telefono,correo,zapato,talla,inscripcion,fechaAlta FROM alumnos WHERE id_alumnos='".$id."'",$link)or die(mysql_error());
if(empty(
$id))
{
echo 
"<script languaje='javascript'> alert('Debes colocar un id'); </script>";

$sql1=mysql_query("SELECT status FROM alumnos");
$res=mysql_fetch_array($sql);
if(
$res[4]==1)
{ echo 
"<script languaje='javascript'> alert('Este alumno tiene adeudos'); </script>";
}else
{ echo 
"<script languaje='javascript'> alert('El alumno no tiene adeudos'); </script>";
}
mysql_close($link);


//}
?>
Espero puedan ayudarme
Muchas Gracias
  #2 (permalink)  
Antiguo 23/03/2010, 01:36
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: get y post en un mismo formulario

Especifica el metodo como POST y agrega las variables que deseas enviar por GET en la accion del formulario:

<form method="post" action="procesa.php?get1=algo&amp;get2=otraCosa&amp;get3=mas">
<input type="text" name="post1" value="Campo enviado por POST" />
<input type="submit" value="Enviar" />
</form>
__________________
- León, Guanajuato
- GV-Foto

Etiquetas: metodos, postear, formulario
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 02:13.