Foros del Web » Programando para Internet » PHP »

redireccionar según opción elegida en formulario

Estas en el tema de redireccionar según opción elegida en formulario en el foro de PHP en Foros del Web. Hola: Tengoun formulario de registro y me gustaría que según la opción elegida ("perro","gato"u "otro") en el campo "especie", redireccione una página u otra, ya ...
  #1 (permalink)  
Antiguo 03/04/2012, 01:18
 
Fecha de Ingreso: octubre-2011
Mensajes: 160
Antigüedad: 12 años, 6 meses
Puntos: 2
Pregunta redireccionar según opción elegida en formulario

Hola:
Tengoun formulario de registro y me gustaría que según la opción elegida ("perro","gato"u "otro") en el campo "especie", redireccione una página u otra, ya que según la elección, es un perfil totalmente diferente. Ahora mismo no estoy preguntando como mostrar los datos, sólo redireccionar, porque me da este fallo:
Código HTML:
Warning: Cannot modify header information - headers already sent by (output started at /homepages/21/d386748216/htdocs/conexion.php:9) in /homepages/21/d386748216/htdocs/registrandose.php on line 80
En concreto esta línea es:
Código HTML:
header ("location: perfilperro.php");
Este es el código de registrandose.php:
Código PHP:
<?php
//se conecta a la base de datos hace la conexion
include("conexion.php");
function 
formRegistro(){}

//el codigo isset es para verificar si se ha enviado el fomulario ya que esta incluido en el php de insertar registro
if(isset ($_POST["usuario"])){
//recojemos los datos del dueño
$nombreamo trim($_POST["nombreamo"]); $telefono $_POST["telefono"]; $email trim($_POST["email"]);
$usuario trim($_POST["usuario"]); $contrasenna trim($_POST["contrasenna"]); $repcontrasenna trim($_POST["repcontrasenna"]); 
$pais $_POST["pais"]; $provincia $_POST["provincia"]; $zona $_POST["zona"];
$ciudad $_POST["ciudad"];

//recojemos los datos del animal
$raza $_POST["raza"]; $edad $_POST["edad"]; $sexo $_POST["sexo"]; $capa $_POST["capa"];
$pedigri $_POST["pedigri"]; $especie $_POST["especie"];

//comprobamos que los campos criticos no esten en blanco y limpiamos la variables de error
//puedes adaptar el codigo obviamente para que muestre un mensaje como clave no coincide etc yo me limite a ponerle una marca de error ya con cada definicion puedes modificar el codigo como gustes
$error_amo "";  $error_email ""$error_user ""$error_contr "";
$error_repcontr ""$error_prov ""$error_raza ""$error_edad ""$error_tel "";

//ejecutamos la consulta en busqueda de usuario o email
$sqluser mysql_query("SELECT usuario, email FROM usuarios WHERE usuario = '$usuario' OR email = '$email'"); 
$total mysql_num_rows($sqluser);

if(
$nombreamo==''){$error_amo "error";}elseif($telefono==''){$error_tel "error";}elseif($email=='' or $total>0){$error_email "error";}elseif($usuario=='' or $total>0){$error_user "error";}elseif($contrasenna=='' && $repcontrasenna==''){$error_contr "error"$error_repcontr "error";}elseif($contrasenna<>$repcontrasenna){$error_contr "error"$error_repcontr "error";}elseif($provincia==''){$error_prov "error";}elseif($raza==''){$error_raza "error";}elseif($edad==''){$error_edad "error";}else{

//comprobamos la imagen y la extension
  //array de archivos disponibles
  
$archivos_disp_ar = array('jpg''jpeg''gif''png''tif''tiff''bmp');
  
//carpteta donde vamos a guardar la imagen
  
$carpeta 'imagen/';
  
//recibimos el campo de imagen
  
$imagen $_FILES['imagen']['tmp_name'];
  
//guardamos el nombre original de la imagen en una variable
  
$nombrebre_orig $_FILES['imagen']['name'];
 
  
//el proximo codigo es para ver que extension es la imagen
  
$array_nombre explode('.',$nombrebre_orig);
  
$cuenta_arr_nombre count($array_nombre);
  
$extension strtolower($array_nombre[--$cuenta_arr_nombre]);
  
//recibimos el tamaño
  
$tamano$_FILES['imagen']['size'];
  
//limitamos el tamaño de la imagen
if($tamano 100000 && $archivos_disp_ar==true )
   
$error "Este tipo de archivo no es permitido"$error_img "error"

  
//validamos la extension
  
if(!in_array($extension$archivos_disp_ar))
 
   
$error "Este tipo de archivo no es permitido"$error_img "error"
  
  if(empty(
$error)){
  
      
//creamos nuevo nombre para que tenga nombre unico
      
$nombre_nuevo time().'_'.rand(0,100).'.'.$extension;
      
//nombre nuevo con la carpeta
      
$nombre_nuevo_con_carpeta $carpeta.$nombre_nuevo;
      
//por fin movemos el archivo a la carpeta de imagenes
      
$mover_archivos move_uploaded_file($imagen $nombre_nuevo_con_carpeta);
      
//de damos permisos 777
      
chmod($nombre_nuevo_con_carpeta,0777);
      
       
// finalmente guardamos todo
       
mysql_query("INSERT INTO usuarios(nombreamo, telefono, email, usuario, contrasenna, ciudad, provincia, pais, zona)
VALUES('{$nombreamo}','{$telefono}','{$email}','{$usuario}','{$clave}','{$ciudad}','{$provincia}','{$pais}','{$zona}')"
);

$idusuario mysql_insert_id(); 
    
mysql_query("INSERT INTO animal(idusuario, usuario, raza, edad, sexo, capa, pedigri, especie, nombreamo)
VALUES('{$idusuario}','{$usuario}','{$raza}','{$edad}','{$sexo}','{$capa}','{$pedigri}','{$especie}','{$nombreamo}')"
);


mysql_query("INSERT INTO fotos(idusuario,nombre_nuevo_con_carpeta)VALUES('{$idusuario}','{$nombre_nuevo_con_carpeta}')");
//aqui pones lo que quieras si lo quieres redireccionar al login bueno eso fue lo que yo hice
if($especie=='perro'){
//aqui te mandara a la pagina que hayas hecho con los estilos y imagenes de perros
header ("location: perfilperro.php");
}
elseif(
$especie=='gato'){
//aqui te mandara a la pagina que hayas hecho con los estilos y imagenes de gatos
header ("location: perfilgato.php");
}else{
//aqui te mandara a la pagina que hayas hecho con los estilos y imagenes
header ("location: perfilotro.php");
}

} }
}else{}
?>
  #2 (permalink)  
Antiguo 03/04/2012, 01:28
 
Fecha de Ingreso: octubre-2011
Mensajes: 160
Antigüedad: 12 años, 6 meses
Puntos: 2
Respuesta: redireccionar según opción elegida en formulario

El formulario(he quitado códigos de seguridad):
Código PHP:
<?php include("registrandose.php"?>
<html>
<head>
</head>
<body class="fondoregistro">
<form action="registro.php" method="post" enctype="multipart/form-data" name="form" id="form">
  <table width="1024" height="768" border="0">
    <tr>
      <td width="304" height="768"><table width="100%" height="618" border="0">
        <tr>
          <td height="350" colspan="2"><img src="images/cancelar.png" alt="" width="<?php if($error_img=='error'){echo '60';}else{echo '0';} ?>" height="<?php if($error_img=='error'){echo '60';}else{echo '0';} ?>" class="xsubir" /></td>
        </tr>
        <tr>
          <td width="84%" height="46">
          <label for="imagen"></label>
            <input name="imagen" type="file" class="subirfoto"  id="imagen" value="<?php echo $_FILES['imagen']['tmp_name']; ?>" size="12" />
            </td>
          <td width="16%"><input name="button" type="submit"  class="botonenvio" id="button" value="Enviar" /></td>
        </tr>
        <tr>
          <td height="148" colspan="2"><span class="style2"><?php echo $error?></span></td>
        </tr>
      </table></td>
      <td width="335"><table width="100%" height="768" border="0">
        <tr>
          <td height="103">&nbsp;</td>
        </tr>
        <tr>
          <td height="60"><label for="pais"></label>
            <input name="pais" type="text" class="pais" id="pais" value="<?php echo $_POST["pais"] ; ?>" maxlength="40" /></td>
        </tr>
        <tr>
          <td height="21" class="imagenx"><?php if($error_prov=='error'){echo '<span style=color:red>erraste';}else{echo '<span style=color:green> acertaste';} ?></td>
        </tr>
        <tr>
          <td height="52"><label for="provincia"></label>
            <input name="provincia" type="text" class="provincia" id="provincia" value="<?php echo $_POST["provincia"] ; ?>" maxlength="40" /><img src="images/cancelar.png" alt="" width="<?php if($error_prov=='error'){echo '30';}else{echo '0';} ?>" height="<?php if($error_prov=='error'){echo '30';}else{echo '0';} ?>" /></td>
        </tr>
        <tr>
          <td height="15">&nbsp;</td>
        </tr>
        <tr>
          <td height="57"><label for="ciudad"></label>
            <input name="ciudad" type="text" class="ciudad" id="ciudad" value="<?php echo $_POST["ciudad"] ; ?>" maxlength="40" /></td>
        </tr>
        <tr>
          <td height="5">&nbsp;</td>
        </tr>
        <tr>
          <td height="45"><label for="zona"></label>
            <input name="zona" type="text" class="zona" id="zona"value="<?php echo $_POST["zona"] ; ?>" maxlength="40" /></td>
        </tr>
        <tr>
          <td height="21"> </td>
        </tr>
        <tr>
          <td height="50"><label for="especie"></label>
          <select name="especie" class="especie" id="sexo">
<option value="perro" <?php if (!(strcmp("perro"$_POST["especie"]))) {echo "selected=\"selected\"";} ?>>perro</option>
<option value="gato" <?php if (!(strcmp("gato"$_POST["especie"]))) {echo "selected=\"selected\"";} ?>>gato</option>
<option value="otro" <?php if (!(strcmp("otro"$_POST["especie"]))) {echo "selected=\"selected\"";} ?>>otro</option>
            </select>
           </td>
        </tr>
        <tr>
          <td height="15" class="imagenx"><?php if($error_raza=='error'){echo '<span style=color:red>erraste';}else{echo '<span style=color:green> acertaste';} ?></td>
        </tr>
        <tr>
          <td height="57"><label for="raza"></label>
            <input name="raza" type="text" class="raza" id="raza" value="<?php echo $_POST["raza"] ; ?>" maxlength="40" /><img src="images/cancelar.png" alt="" width="<?php if($error_raza=='error'){echo '30';}else{echo '0';} ?>" height="<?php if($error_raza=='error'){echo '30';}else{echo '0';} ?>" /></td>
        </tr>
        <tr>
          <td height="5" class="imagenx"><?php if($error_edad=='error'){echo '<span style=color:red>erraste';}else{echo '<span style=color:green> acertaste';} ?></td>
        </tr>
        <tr>
          <td height="45"><label for="edad"></label>
            <input name="edad" type="text" class="edad" id="edad" onkeyUp="return ValNumero(this);" value="<?php echo $_POST["edad"] ; ?>" maxlength="3" /><img src="images/cancelar.png" alt="" width="<?php if($error_edad=='error'){echo '30';}else{echo '0';} ?>" height="<?php if($error_edad=='error'){echo '30';}else{echo '0';} ?>" /></td>
        </tr>
        <tr>
          <td height="15">&nbsp;</td>
        </tr>
        <tr>
          <td height="61"><label for="sexo"></label>
            <select name="sexo" class="sexo" id="sexo">
<option value="hembra" <?php if (!(strcmp("hembra"$_POST["sexo"]))) {echo "selected=\"selected\"";} ?>>hembra</option>
<option value="macho" <?php if (!(strcmp("macho"$_POST["sexo"]))) {echo "selected=\"selected\"";} ?>>macho</option>
            </select></td>
        </tr>
        <tr>
          <td height="46">&nbsp;</td>
        </tr>
      </table></td>
      <td width="371"><table width="100%" height="768" border="0">
        <tr>
          <td height="103" colspan="2">&nbsp;</td>
        </tr>
        <tr>
          <td width="43%" height="60"><input name="pedigri" type="radio" class="si" id="radio" value="si" <?php if (!(strcmp("si"$_POST["pedigri"]))) {echo "selected=\"selected\"";} ?> checked="checked" />
            <label for=""></label></td>
          <td width="57%"><input name="pedigri" type="radio" class="no" id="radio2" value="no" <?php if (!(strcmp("no"$_POST["pedigri"]))) {echo "selected=\"selected\"";} ?> />
            <label for="radio2"></label></td>
        </tr>
        <tr>
          <td height="21" colspan="2">&nbsp;</td>
        </tr>
        <tr>
          <td height="52" colspan="2"><label for="capa"></label>
            <input name="capa" type="text" class="capa" id="capa" value="<?php echo $_POST["capa"] ; ?>" maxlength="20" /></td>
        </tr>
        <tr>
          <td height="15" colspan="2" class="imagenx"><?php if($error_amo=='error'){echo '<span style=color:red>erraste';}else{echo '<span style=color:green> acertaste';} ?></td>
        </tr>
        <tr>
          <td height="57" colspan="2"><label for="nombreamo"></label>
            <input name="nombreamo" type="text" class="nombreamo" id="nombreamo" value="<?php echo $_POST["nombreamo"] ; ?>" maxlength="30" />
            <img src="images/cancelar.png" width="<?php if($error_amo=='error'){echo '30';}else{echo '0';} ?>" height="<?php if($error_amo=='error'){echo '30';}else{echo '0';} ?>" /></td>
        </tr>
        <tr>
          <td height="5" colspan="2" class="imagenx"><?php if($error_tel=='error'){echo '<span style=color:red>erraste';}else{echo '<span style=color:green> acertaste';} ?></td>
        </tr>
        <tr>
          <td height="45" colspan="2"><label for="telefono"></label>
            <input name="telefono" type="text" class="telefono" id="telefono" onkeyUp="return ValNumero(this);" value="<?php echo $_POST["telefono"]; ?>" maxlength="15" /><img src="images/cancelar.png" alt="" width="<?php if($error_tel=='error'){echo '30';}else{echo '0';} ?>" height="<?php if($error_tel=='error'){echo '30';}else{echo '0';} ?>" /></td>
        </tr>
        <tr>
          <td height="21" colspan="2" class="imagenx"><?php if($error_email=='error'){echo '<span style=color:red>erraste';}else{echo '<span style=color:green> acertaste';} ?></td>
        </tr>
        <tr>
          <td height="50" colspan="2"><label for="email"></label>
            <input name="email" type="text" class="email" id="email" value="<?php echo $_POST["email"] ; ?>" maxlength="35" /><img src="images/cancelar.png" alt="" width="<?php if($error_email=='error'){echo '30';}else{echo '0';} ?>" height="<?php if($error_email=='error'){echo '30';}else{echo '0';} ?>" /></td>
        </tr>
        <tr>
          <td height="15" colspan="2" class="imagenx"><?php if($error_user=='error'){echo '<span style=color:red>erraste';}else{echo '<span style=color:green> acertaste';} ?></td>
        </tr>
        <tr>
          <td height="57" colspan="2"><label for="usuario"></label>
            <input name="usuario" type="text" class="usuario" id="usuario" value="<?php echo $_POST["usuario"] ; ?>" maxlength="40" /><img src="images/cancelar.png" alt="" width="<?php if($error_user=='error'){echo '30';}else{echo '0';} ?>" height="<?php if($error_user=='error'){echo '30';}else{echo '0';} ?>" /></td>
        </tr>
        <tr>
          <td height="5" colspan="2" class="imagenx"><?php if($error_contr=='error'){echo '<span style=color:red>erraste';}else{echo '<span style=color:green> acertaste';} ?></td>
        </tr>
        <tr>
          <td height="45" colspan="2"><label for="contrasenna"></label>
            <input name="contrasenna" type="password" class="contrasena" id="contrasenna" value="<?php echo $_POST["contrasenna"]; ?>" onclick='contrasenna.value=""' maxlength="25" /><img src="images/cancelar.png" alt="" width="<?php if($error_contr=='error'){echo '30';}else{echo '0';} ?>" height="<?php if($error_contr=='error'){echo '30';}else{echo '0';} ?>" /></td>
        </tr>
        <tr>
          <td height="15" colspan="2" class="imagenx"><?php if($error_repcontr=='error'){echo '<span style=color:red>erraste';}else{echo '<span style=color:green> acertaste';} ?></td>
        </tr>
        <tr>
          <td height="61" colspan="2"><label for="repcontrasenna"></label>
            <input name="repcontrasenna" type="password" class="repcontrasenna" id="repcontrasenna" value="<?php echo $_POST["contrasenna"]; ?>" onclick='repcontrasenna.value=""' maxlength="25" /><img src="images/cancelar.png" alt="" width="<?php if($error_repcontr=='error'){echo '30';}else{echo '0';} ?>" height="<?php if($error_repcontr=='error'){echo '30';}else{echo '0';} ?>" /></td>
        </tr>
        <tr>
          <td height="46" colspan="2">&nbsp;</td>
        </tr>
      </table></td>
    </tr>
  </table>
</form>
</body>
</html>
  #3 (permalink)  
Antiguo 03/04/2012, 12:27
 
Fecha de Ingreso: octubre-2011
Mensajes: 160
Antigüedad: 12 años, 6 meses
Puntos: 2
Respuesta: redireccionar según opción elegida en formulario

¿Nadie tiene una pequeña idea de por dónde puede andar el fallo por favor?

Etiquetas: formulario.php, redirección
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 10:39.