Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/01/2011, 04:57
eduh4l
 
Fecha de Ingreso: enero-2011
Mensajes: 9
Antigüedad: 13 años, 4 meses
Puntos: 0
Duda Redirigir - PHP

Hola, buenos dias gente de forosdelweb.
Tengo una pequeña duda sobre PHP, os explico.

Necessito hacer una gestion de una base de datos.

Tengo un documento llamado "crear.php" con el que introduzco datos a la BBDD, pero me gustaria que una vez introducidos los campos, me redirigiese al archivo "mostrar.php".

He hecho un
Código PHP:
header ("Location: mostrar.php"); 
, pero me muestra el siguiente error;Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\eduard\SQL\crear.php:8) in C:\xampp\htdocs\eduard\SQL\crear.php on line 70

Aqui os dejo el codigo del archivo "crear.php";

Código PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
</head>
<body>
    <?php
     
if (empty($_POST)) { //Fem una condició dient que si la variable $_POST està buida mostri el següent:
         
?>
     
    <FORM Name ="Array" Method ="POST" ACTION = "crear.php">
        <H2 align="center"> Introduïr dades </H2><br><br>
          <TABLE BORDER="1" BORDERCOLOR="black" CELLPADDING="5" CELLSPACING="5" WIDTH="39%" align="center">
                        <tr>
                            <td>
                                Nom <input type=text size=”19” name="nom" maxlenght=”5”>
                            </td>
                            <td>
                                Cognoms <input type=text name="cognom" size=“30”>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                DNI <input type=text name="dni" size=“9” value="-">
            
                            </td>
                            <td>
                                Data de Naixement <input type=text name="data" size=“10” value="yyyy/mm/dd">
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" align="center">
                                Sexe: <SELECT name="sexe">
                                    <OPTION VALUE="home">Home</OPTION>
                                    <OPTION VALUE="dona">Dona</OPTION>
                                    </SELECT>
                            </td>
                        </tr>
                        <tr>
                            <td align="center">
                                <INPUT type="submit" value="Crear">
                            </td>
                            <td align="center">
                                <INPUT type="reset" value="Reinicia">
                            </td>
                        </tr>
                    </TABLE>
                </FORM>
        <?php
        
} else { //Si no està buida la variable $_POST, farem el següent:
    //Array:
    
$resultat[nom] = $_POST['nom'];
    
$resultat[cognom] = $_POST['cognom'];
    
$resultat[dni] = $_POST['dni'];
    
$resultat[sexe] = $_POST['sexe'];
    
$resultat[data] = $_POST['data'];

         if (empty (
$resultat[nom]) or empty ($resultat[cognom]) or empty ($resultat[dni]) or empty ($resultat[data])) { //Condició que si algun camp està buit mostri el següent:
                
echo "Algun camp està buit, has d'omplir-los tots !";
            } else {
        
$connectar = @mysqli_connect(localhost,"root","","eduard");
    if (!
$connectar) die( "No puc obrir la Base de Dades");

   
$afegir="INSERT INTO clients (Nom, Cognoms, DNI, Sexe, Naixement) VALUES ('$resultat[nom]','$resultat[cognom]','$resultat[dni]','$resultat[sexe]','$resultat[data]')";
  
mysqli_query($connectar$afegir);
      
mysqli_close($connectar); //Tanca la base de dades
            
}
        }
    
?>
</body>
</html>
Donde deveria poner el "Header" para que me funcionase correctamente ?

Muchisimas gracias