epox 0 Report post Posted August 1, 2005 (edited) hello!, i'm practicing with php sending mails, manipulating databases, and everything is going right, but when i try to redirect the browser to a page with header("Location: mysite.html"); after it ends the transactions, the navigator shows an error and don't redirects the browser, the error is: Warning: Cannot modify header information - headers already sent by (output started at /home/epox/public_html/contacto.php:9) in /home/epox/public_html/contacto.php on line 13if someone knows how to correct the error i will be so gratefuly. Notice from BuffaloHELP: You MUST use quote tags whenever you are copying. Edited August 2, 2005 by BuffaloHELP (see edit history) Share this post Link to post Share on other sites
truefusion 3 Report post Posted August 2, 2005 It be much easier for us to help you in this problem if you actually showed us the coding. Share this post Link to post Share on other sites
rvalkass 5 Report post Posted August 2, 2005 That error normally appears if you try to set a header after it has already been sent. Headers must be set before the script outputs anything to the browser or any action is taken like that. If you need to force another page, try using some simple javascript. Share this post Link to post Share on other sites
palladin 0 Report post Posted August 2, 2005 Moe php code before html tags <head> </head> starts. I guest this is can help but if not the code is very helpfull --------------------Practice is when evrything is work but no one know why.Theory is when work nothing but evry one know why.Programmers join Practice with Theory - nothing work and no one know why Share this post Link to post Share on other sites
snlildude87 0 Report post Posted August 2, 2005 The code header("Location: mysite.html"); MUST be put at the very beginning of your code...before headers are sent. That's basically all I can tell you without looking at the code.You can also try my script: http://forums.xisto.com/topic/20516-email-scriptform-with-php-how-to-make-a-simple-email-script-using-php/ Share this post Link to post Share on other sites
epox 0 Report post Posted August 3, 2005 (edited) helloo!, here goes the code: this is the php code: <?php $dbh=mysql_connect ("localhost", "epox", "******") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("epox_tribusuburbanas"); $nombre=$_GET['nombre']; $mail=$_GET['mail']; $movil=$_GET['movil']; $fijo=$_GET['fijo']; mysql_query("insert into agenda values ('$nombre','$mail','$movil','$fijo')",$dbh); header("agenda.htm");?> and here the htm: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://forums.xisto.com/no_longer_exists/ http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Agenda</title><style type="text/css">body{ margin-top: 20px; text-align: center; background-color: #666;}#container{ background-color: #3399FF; border: 1px solid #fff; margin-right: auto; margin-left: auto; padding: 0px 10px 10px 0px; width: 300px;}#header{ background-color:#FF9900;} #header h3{ margin: 0px; padding: 10px; font-size: 20px; color: #fff; font-weight: normal;}#form{ padding-left: 10px; padding-top: 10px; color: #CCCCCC; text-align: left;} </style></head><body> <div id="container"> <div id="header"><h3>Agenda</h3></div> <div id="form"> <form name="agenda" action="agenda.php"> <input type="text" name="nombre"> Nombre<br> <input type="text" name="mail"> eMail<br> <input type="text" name="movil"> Movil<br> <input type="text" name="fijo"> Fijo<br> <input type="submit" value="enviar"> </form> </div> </div></body></html> well that's all, thank you for any colaboration! Notice from snlildude87: Fixed BBCode Edited August 4, 2005 by snlildude87 (see edit history) Share this post Link to post Share on other sites
electriic ink 1 Report post Posted August 4, 2005 I do not mysql much but don't you have to close the connection with the database? Try putting mysql_close(); before the header command. Also, I've just noticed, that that's not how you redirect someone with php. It should be: header("location:agenda.htm"); Try these small changes and then see if it works Share this post Link to post Share on other sites
SystemWisdom 0 Report post Posted August 4, 2005 helloo!, here goes the code: this is the php code: <?php $dbh=mysql_connect ("localhost", "epox", "******") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("epox_tribusuburbanas"); $nombre=$_GET['nombre']; $mail=$_GET['mail']; $movil=$_GET['movil']; $fijo=$_GET['fijo']; mysql_query("insert into agenda values ('$nombre','$mail','$movil','$fijo')",$dbh); header("agenda.htm");?> [...] 169650[/snapback] Make sure you have NO whitespace before your <?php tag, as that whitespace will cause PHP to start outputting to the browser, which in turn causes the default headers to be sent... Also, you should specify the full URL to the file to redirect to.. This quote is from PHP.net on the subject: Note: HTTP/1.1 requires an absolute URI as argument to Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself: <?phpheader("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/" . $relative_url);?> I hope that helps!! Share this post Link to post Share on other sites