Biomehanika
Biomehanika

Reputation: 1540

header('Location: http://google.com'); not working

I am now on *Gestion/config/forms/school_main/school_main.php*. When I submit the form contained here, header does not redirect me to http://google.com as I've set, it redirects me to *Gestion/school_main.php*, resulting on an error as that directory does not have that document.

What's the reason for header not to be working? Any help? I am on localhost, ant this worked perfectly till today that I made a code cleaning... Thank you.

Oh, I add: it neither inserts or updates any info on BBDD

You have the entire form code here: http://www.snipplr.com/view/73556/problem-header2/

HEADER CODE:

    if (mysql_num_rows($consultaCampos)==0) {
    $nuevoRegistro = mysql_query("INSERT INTO school_main(sc_id,sc_name,sc_cif,sc_web,sc_headmstr,sc_studDirector,sc_dir1,sc_dir2,sc_dir3,sc_dir4,sc_postcode,sc_pobl,sc_city,sc_country,sc_tel1sec,sc_tel1,sc_tel2sec,sc_tel2,sc_fax,sc_mail1sec,sc_mail1,sc_mail2sec,sc_mail2,sc_mail3sec,sc_mail3,sc_img) VALUE ('','$nombre','$cif','$web','$director','$jefeEstudios','$direccion1','$direccion2','$direccion3','$direccion4','$codigopostal','$poblacion','$ciudad','$pais','$seccionTelefono1','$telefonol','$seccionTelefono2','$telefono2','$fax','$seccionEmail1','$email1','$seccionEmail2','$email2','$seccionEmail3','$email3','$rutaFinal')") or exit("No se pudo introducir contenido en la base de datos");

        header('Location: http://google.com');
exit;
}

else{
    $idCentro=$registroBbdd['sc_id'];
    $actualizaRegistro = mysql_query("UPDATE school_main SET sc_name='$nombre',sc_cif='$cif',sc_web='$web',sc_headmstr='$director',sc_studDirector='$jefeEstudios',sc_dir1='$direccion1',sc_dir2='$direccion2',sc_dir3='$direccion3',sc_dir4='$direccion4',sc_postcode='$codigopostal',sc_pobl='$poblacion',sc_city='$ciudad',sc_country='$pais',sc_tel1sec='$seccionTelefono1',sc_tel1='$telefonol',sc_tel2sec='$seccionTelefono2',sc_tel2='$telefono2',sc_fax='$fax',sc_mail1sec='$seccionEmail1',sc_mail1='$email1',sc_mail2sec='$seccionEmail2',sc_mail2='$email2',sc_mail3sec='$seccionEmail3',sc_mail3='$email3',sc_img='$rutaFinal' WHERE sc_id='$idCentro'") or exit("No se pudo actualizar el contenido de la base de datos");


    header('Location: http://google.com');
exit;

}

Upvotes: 0

Views: 553

Answers (3)

biw
biw

Reputation: 3085

I believe your problem is how you are handling your variables.

If you have any variable missing you will get

Notice: Undefined index: sc_tel1sec in page.php on line 26

In order for the header to work, all variables must be defined. Even if one variable is undefined the header function will not work. Try turning on errors in php.ini to check it.

try if ( !empty( $_POST['sc_var'] ) ) { $var = $_POST['sc_var']; }

on all related variables.

Upvotes: 0

Dador
Dador

Reputation: 5425

Probably problem is that you do ob_start() in first line of your script but don't do ob_end_flush() before using exit().

Upvotes: 0

Krish R
Krish R

Reputation: 22721

Should be

 ) VALUES (

instead of

) VALUE (

in your insert query

Try this,

 $nuevoRegistro = mysql_query("INSERT INTO school_main (...) VALUES (...)") or die("No se pudo introducir contenido en la base de datos".mysql_error());

Upvotes: 1

Related Questions