View Full Version : PHP Error
ghobro
June 18th, 2001, 16:36
When i run my php pages, error :
Warning: Cannot add header information - headers already sent by (output started at /home/pdfci/index.phtml:9) in /home/pdfci/index.phtml on line 30
ghobro
June 18th, 2001, 17:00
Here code :
<html>
<head>
<title>Ghobro Homepage</title>
</head>
<body>
<center>Ghobro Homepages</center>
<?
$db_name = "mystif";
$table_name = "redirects";
$cnx = mysql_connect("localhost","mystif","askrag")
or die("Couldn't connect.");
$db = mysql_select_db($db_name, $cnx)
or die("Couldn't select database.");
$sql = "SELECT id, address FROM $table_name
WHERE id = '$id'";
$result = mysql_query($sql,$cnx)
or die("Couldn't execute query.");
while ($row = @mysql_fetch_array($result)) {
$id = $row["id"];
$address = $row["address"];
}
header("location: $address");
?>
<a href=index.phtml?id=1>Ghobro</a>
</body>
</html>
lucifer
June 18th, 2001, 17:20
you are trying to set a header after you have provided some output.
headers must be set before you output any of your page
put your php at the top of the page before <HTML>
gyrbo
June 19th, 2001, 09:05
The compete code
Originally posted by ghobro
Here code :
<?
$db_name = "mystif";
$table_name = "redirects";
$cnx = mysql_connect("localhost","mystif","askrag")
or die("Couldn't connect.");
$db = mysql_select_db($db_name, $cnx)
or die("Couldn't select database.");
$sql = "SELECT id, address FROM $table_name
WHERE id = '$id'";
$result = mysql_query($sql,$cnx)
or die("Couldn't execute query.");
while ($row = @mysql_fetch_array($result)) {
$id = $row["id"];
$address = $row["address"];
}
header("location: $address");
?>
<html>
<head>
<title>Ghobro Homepage</title>
</head>
<body>
<center>Ghobro Homepages</center>
<a href=index.phtml?id=1>Ghobro</a>
</body>
</html>
lucifer
June 19th, 2001, 10:17
does it work now?
you should xxxxxx out your passwords :)
gyrbo
June 19th, 2001, 14:55
True, but we don't know his host.(Yes we do: localhost, are they good anyone heard any good of them :D)
lucifer
June 19th, 2001, 17:01
Sorry I get the two of you confused :confused: :o
ghobro
June 20th, 2001, 04:52
I have replace my code with gyrbo instructions, but still error.
http://pdfci.home.dk3.com
lucifer
June 20th, 2001, 05:02
do you have a blank line at the top?
<? must be the first characters on the page
if there's a space it's output so then the header can't be sent
ghobro
June 20th, 2001, 23:31
Ok. Thx all. My site running now.
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.