Forum Moderators: coopster
Warning: Cannot modify header information - headers already sent by (output started at
I read in several places that this involves blank spaces ahead of the <?. I've check for this but still have the issue. I've posted the code below, and suggestions?
<?
include_once "../conn.php";
if (isset($_POST[s1]))
{
$q1 = "insert into job_employer_info set
ename = \"$_POST[ename]\",
epass = \"$_POST[epass]\",
ContactName = '$_POST[ContactName]',
position = '$_POST[position]',
YearEstablished = '$_POST[YearEstablished]',
capital = '$_POST[capital]',
employees = '$_POST[employees]',
CompanyName = \"$_POST[CompanyName]\",
CompanyCountry = \"$_POST[CompanyCountry]\",
CompanyState = \"$_POST[CompanyState]\",
CompanyZip = \"$_POST[CompanyZip]\",
CompanyCity = \"$_POST[CompanyCity]\",
street = \"$_POST[street]\",
CompanyAddress = \"$_POST[CompanyAddress]\",
CompanyPhone = \"$_POST[CompanyPhone]\",
CompanyPhone2 = \"$_POST[CompanyPhone2]\",
fax = \"$_POST[fax]\",
CompanyEmail = \"$_POST[CompanyEmail]\"";
$r1 = mysql_query($q1);
if(mysql_error())
{
$error = "<br><span class=TNA>Duplicate username: $_POST[ename]</span>";
unset($_POST[ename]);
}
else
{
$to = $CompanyEmail;
$subject = "Your account at $_SERVER[HTTP_HOST]";
$message = "This is your account information at $_SERVER[HTTP_HOST]\n\n username: $_POST[ename]\n password: $_POST[epass]\n\n\n Keep this information in a secure place. \n\n Thanks for your registration. We believe you will find the staff you need at [$_SERVER[HTTP_HOST]...] ";
$from = "From: $_SERVER[HTTP_HOST] <$aset[ContactEmail]>";
mail($to, $subject, $message, $from);
$_SESSION[ename] = $_POST[ename];
header("Location:thanks.php");
exit();
}
}
include_once "../main.php";
?>
[edited by: eelixduppy at 2:12 pm (utc) on June 15, 2008]
[edit reason] removed excess HTML [/edit]
You cannot have any output to the browser before your HEADER() function otherwise the headers will not be able to be modified as they were already sent to the browser. Check to see if whitespace, HTML, etc has been echoed to the browser at any time before the header() call; you should also check your included files.
conn.php
<?
$dbe_host = "***********";
$dbe_username = "********";
$dbe_password = "********";
$dbe_name = "*********";
$script_dir = "";
$connection = mysql_connect($db_host, $db_username, $db_password) or die(mysql_error());
$db = mysql_select_db($db_name, $connection);
if(!empty($script_dir))
{
$dir = "/".$script_dir;
}
$qset = "select * from job_settings";
$rset = mysql_query($qset) or die(mysql_error());
$aset = mysql_fetch_array($rset);
$t = time();
function select_country($c, $n)
{
$s = "<select name=\"$n\">\n\t";
$countries = array('Afghanistan', 'Albania', 'American Samoa', 'Andorra', 'Antigua', 'Argentina', 'Armenia', 'Australia', 'Austria', 'Azerbaijan', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium', 'Belize', 'Bolivia', 'Bosnia-Herzegovina', 'Brazil', 'Brunei Darussalam', 'Bulgaria', 'Cambodia', 'Canada', 'Chile', 'China', 'Colombia', 'Costa Rica', 'Croatia', 'Cuba', 'Cyprus', 'Czech Republic', 'Denmark', 'Ecuador', 'Egypt', 'El Salvador', 'Estonia', 'Falkland Islands', 'Fiji', 'Finland', 'France', 'French Guyana', 'Georgia', 'Germany', 'Gibraltar', 'Greece', 'Greenland', 'Grenada', 'Guatemala', 'Honduras', 'Hong Kong', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Iran', 'Iraq', 'Ireland', 'Israel', 'Italy', 'Japan', 'Jordan', 'Kazakhstan', 'Kenya', 'Kuwait', 'Kyrgyzstan', 'Laos', 'Latvia', 'Lebanon', 'Libya', 'Liechtenstein', 'Lithuania', 'Luxembourg', 'Malaysia', 'Maldives', 'Malta', 'Mauritius', 'Mexico', 'Mongolia', 'Morocco', 'Nepal', 'Netherlands', 'New Zealand', 'Nicaragua', 'North Korea', 'Norway', 'Oman', 'Pakistan', 'Panama', 'Paraguay', 'Peru', 'Philippines', 'Poland', 'Portugal', 'Puerto Rico', 'Qatar', 'Romania', 'Russian Federation', 'Saudi Arabia', 'Singapore', 'Slovak Republic', 'Slovenia', 'South Africa', 'South Korea', 'Spain', 'Sri Lanka', 'Sweden', 'Switzerland', 'Syria', 'Taiwan', 'Thailand', 'Tunisia', 'Turkey', 'Turkmenistan', 'Ukraine', 'United Arab Emirates', 'United Kingdom', 'USA', 'Uruguay', 'Uzbekistan', 'Venezuela', 'Vietnam', 'Yemen', 'Yugoslavia', 'Zimbabwe');
while(list(,$v) = each($countries))
{
if(!empty($c))
{
if($c == $v)
{
$s .= "<option value=\"$v\" selected>$v</option>\n\t";
}
else
{
$s .= "<option value=\"$v\">$v</option>\n\t";
}
}
else
{
if($v == "USA")
{
$s .= "<option value=\"$v\" selected>$v</option>\n\t";
}
else
{
$s .= "<option value=\"$v\">$v</option>\n\t";
}
}
}
$s .= "</select>\n\n";
return $s;
}
function job_categories($c, $menu_name, $menu_type) {
if(!empty($c))
{
$sc = explode("¦", $c);
}
$categories = array("Accounting/Auditing", "Administrative and Support Services", "Advertising/Public Relations", "Agriculture/Forestry/Fishing", "Architectural Services", "Arts, Entertainment, and Media", "Banking", "Biotechnology and Pharmaceutical", "Community, Social Services, and Nonprofit", "Computers, Hardware", "Computers, Software", "Construction, Mining and Trades", "Consulting Services", "Customer Service and Call Center", "Education, Training, and Library", "Employment Placement Agencies", "Engineering", "Executive Management", "Finance/Economics", "Financial Services", "Government and Policy", "Healthcare, Other", "Healthcare, Practitioner, and Technician", "Hospitality, Tourism", "Human Resources", "Information Technology", "Installation, Maintenance and Repair", "Insurance", "Internet/E-Commerce", "Law Enforcement and Security", "Legal", "Manufacturing and Production", "Marketing", "Military", "Other", "Personal Care and Services", "Real Estate", "Restaurant and Food Service", "Retail/Wholesale", "Sales", "Science", "Sports/Recreation", "Telecommunications", "Transportation and Warehousing");
$select = "<SELECT NAME=\"$menu_name\" $menu_type>\n\t";
while(list(,$v) = each($categories))
{
if(!empty($sc))
{
if(in_array($v, $sc))
{
$select .= "<option value=\"$v\" selected>$v</option>\n\t";
}
else
{
$select .= "<option value=\"$v\">$v</option>\n\t";
}
}
else
{
$select .= "<option value=\"$v\">$v</option>\n\t";
}
}
$select .= "</select>";
return $select;
}
function career_level($c, $id) {
$levels = array("Student (High School)", "Student (undergraduate/graduate)", "Entry Level (less than 2 years of experience)", "Mid Career (2+ years of experience)", "Management (Manager/Director of Staff)", "Executive (SVP, EVP, VP)", "Senior Executive (President, CEO)");
if($id >= '0')
{
$level = $levels[$id];
return $level;
}
else
{
$select = "<select name=\"careerlevel\">\n\t";
while(list($k,$v) = each($levels))
{
if($c >= '0')
{
if($c == $k)
{
$select .= "<option value=\"$k\" selected>$v</option>\n\t";
}
else
{
$select .= "<option value=\"$k\">$v</option>\n\t";
}
}
else
{
$select .= "<option value=\"$k\">$v</option>\n\t";
}
}
$select .= "</select>\n\n";
return $select;
}
}
function target_company($t) {
$tarray = array("Small (up to 99 empl.)", "Medium (100 - 500 empl.)", "Large (over 500 empl.)");
$select = "<select name=\"target_company\">\n\t";
while(list($k,$v) = each($tarray))
{
if($t >= '0')
{
if($t == $k)
{
$select .= "<option value=\"$v\" selected>$v</option>\n\t";
}
else
{
$select .= "<option value=\"$v\">$v</option>\n\t";
}
}
else
{
$select .= "<option value=\"$v\">$v</option>\n\t";
}
}
$select .= "</select>\n\n";
return $select;
}
function select_date($a) {
/*
this function will return 3 drop down menus:
"day" "months" and "years"
The $a value is the seletected date in "Jan/13/2003" format
*/
//transform $a in month number and 4 digit year number
if(!empty($a))
{
$dates = explode("/", $a);
$my_date_month = $dates[0];
$my_date_day = $dates[1];
$my_date_year = $dates[2];
}
////////////////////////////////////////////////////////////
//////////////months menu - start
////////////////////////////////////////////////////////////
$m = "<select name=\"month\">\n\t<option value=\"\"></option>\n\t";
for($i = 1; $i <= 12; $i++)
{
$month = date("M", mktime(0,0,0,date($i),date(d),date(Y)));
if($my_date_month == $month)
{
$m .= "<option value=\"$month\" selected>$month</option>\n\t";
}
else
{
$m .= "<option value=\"$month\">$month</option>\n\t";
}
}
$m .= "</select>";
////////////////////////////////////////////////////////////
//////////////months menu - end
////////////////////////////////////////////////////////////
$m .= "\n\n \n\n";
////////////////////////////////////////////////////////////
//////////////days menu - start
////////////////////////////////////////////////////////////
$m .= "<select name=\"day\">\n\t<option value=\"\"></option>\n\t";
for($i = 1; $i <= 31; $i++)
{
if($my_date_day == $i)
{
$m .= "<option value=\"$i\" selected>$i</option>\n\t";
}
else
{
$m .= "<option value=\"$i\">$i</option>\n\t";
}
}
$m .= "</select>";
////////////////////////////////////////////////////////////
//////////////months menu - end
////////////////////////////////////////////////////////////
$m .= "\n\n \n\n";
////////////////////////////////////////////////////////////
//////////////years menu - start
////////////////////////////////////////////////////////////
$m .= "<select name=\"year\">\n\t<option value=\"\"></option>\n\t";
for($y = date(Y) - 18; $y >= (date(Y) - 70 ); $y--)
{
if($my_date_year == $y)
{
$m .= "<option value=\"$y\" selected>$y</option>\n\t";
}
else
{
$m .= "<option value=\"$y\">$y</option>\n\t";
}
}
$m .= "</select>";
////////////////////////////////////////////////////////////
//////////////years menu - end
////////////////////////////////////////////////////////////
return $m;
}
function select_plan($p) {
$select = "<select name=price>\n\t";
$q1 = "select * from job_prices order by PriceValue";
$r1 = mysql_query($q1) or die(mysql_error());
while($a1 = mysql_fetch_array($r1))
{
$select .= "<option value=\"$a1[PriceID]\">$a1[PriceDesc] ($a1[PriceValue])</option>\n\t";
}
$select .= "</select>";
return $select;
}
function count_info($what) {
/*
This function will count various resources. The parameters can be:
"jobseekers" - return the number of registered jobseekers
"employers" - return the number of registered employers
"resumes" - return the number of resumes
"jobs" - return the number of posted jobs
*/
if($what == "jobseekers")
{
//count the registered jobseekers
$q1 = "select count(uname) from job_seeker_info";
}
elseif($what == "employers")
{
$q1 = "select count(ename) from job_employer_info";
}
elseif($what == "resumes")
{
$q1 = "select count(uname) from job_seeker_info where rTitle != '' ";
}
elseif($what == "jobs")
{
$q1 = "select count(job_id) from job_post";
}
$r1 = mysql_query($q1) or die(mysql_error());
$a1 = mysql_fetch_array($r1);
return $a1[0];
}
function show_counters($f) {
global $dir;
if($f == "on")
{
$jobseekers = count_info("jobseekers");
$employers = count_info("employers");
$resumes = count_info("resumes");
$jobs = count_info("jobs");
$c = "<img src=\"http://$_SERVER[HTTP_HOST]$dir/images/bullet01.gif\" width=\"11\" height=\"11\" alt=\"\" border=\"0\" hspace=\"5\" align=\"absmiddle\">Job Seekers: $jobseekers<br><img src=\"http://$_SERVER[HTTP_HOST]$dir/images/bullet01.gif\" width=\"11\" height=\"11\" alt=\"\" border=\"0\" hspace=\"5\" align=\"absmiddle\">Employers: $employers<br><img src=\"http://$_SERVER[HTTP_HOST]$dir/images/bullet01.gif\" width=\"11\" height=\"11\" alt=\"\" border=\"0\" hspace=\"5\" align=\"absmiddle\">Resumes: $resumes<br><img src=\"http://$_SERVER[HTTP_HOST]$dir/images/bullet01.gif\" width=\"11\" height=\"11\" alt=\"\" border=\"0\" hspace=\"5\" align=\"absmiddle\">Jobs: $jobs<br>\n\n";
return $c;
}
else
{
return false;
}
}
if(!empty($_GET))
{
extract($_GET);
}
if(!empty($_POST))
{
extract($_POST);
}
?>
Again thx for your assistance.
So although I only read part of your code there doesnt seem to be any print or echo statements in there (thank god for ctrl-f), however if there is ANY output before you start you php then the header wont work. So even if you have a blank line before your starting <?php tag you will not be able to send another header.
Please dont post the code for the entire page. Just check it for echo/print statements before the header or any html, even blank lines.
Thank you for the input. I've check the blank lines issue, using a couple different text editors just in case and their are no blank lines before <? in my primary or included php files. I have no print statements in either and the only echo statements I have are for a drop down list in a form. I have removed them as a test but still am getting the same issue.
Any additional thoughts?
Have you tried creating some dummy pages with ob_start(); sending headers after echo statements just to check it is not somekind of server setup? Are you working on a local box or on a live server?