PHP FPDF errors

I am getting the following errors  when I attempt to produce a pdf.

Warning: Cannot modify header information - headers already sent by (output started at /home/content/t/r/a/transconvalue/html/propinsp.php:7) in /home/content/t/r/a/transconvalue/html/fpdf.php on line 1017
FPDF error: Some data has already been output, can't send PDF file.

From what I have been able to research, the header issue is generally caused by blank spaces, but I can't determine where they are.

I'm at a loss on the some data has already been sent.  Thank you.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN http: //www.w3.org/TR/html4/loose.dtd">

<html>
	<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
		<title>Property Inspection Form</title>
		<style type="text/css">
			body {
				background-color: #FFFFFF;
				margin-left: 10%;
				margin-right: 10%;
				border: 2px solid gray;
				padding: 20px 20px 20px 20px;
				font-family: Verdana, Helvetica, Arial, sans-serif;
				}
			table {
				margin-left: 20px;
				margin-right: 20px;
				border: thin solid white;
				caption-side: top;
				background-color: #E6E6FA
				}
			td, th {
                                font-weight: normal; 
                                font-size: 8pt; 
                                color: #000000; 
                                font-family: verdana, arial, helvetica, sans-serif;
                                text-decoration: none;
                                align="center"
				border: 2px solid white;
				padding: 5px;
				text-align: left;
				}
			caption {
				padding-top: 8px;
				}
			#prop_insp_form{
				background-color: #A3C2FF;
                                align="center";
				}
		</style>
	</head>
	<body>
<form enctype="multipart/form-data" method="POST" action="<?php echo $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']; ?>">
<div id="nav">
<ul id="headerNav">
<li><a href="index.php" title="index">Home</a></li>
<li><a href="pending.php" title="Pending">Pending</a></li>
<li class="headerRight"><a href="/logout" title="Logout">Logout</a></li>
</ul>
</div>
<div id="?header?">
<h4><b>Instructions to Broker/Agent</b></h4>
<ul>
<li>Please inspect and complete within 1 business day, unless otherwise agreed upon </li>
</ul>
</div>

<?php
require_once('connvars.php');
require('fpdf.php');
  
 $job_id=$_GET['job_id'];
 $tc_number=$_GET['tc_number'];
 $prop_addr_1=$_GET['prop_addr_1'];
 $prop_city=$_GET['prop_city'];
 $prop_state=$_GET['prop_state'];
 $prop_zip=$_GET['prop_zip'];
 $prop_county=$_GET['prop_county'];


$dbc=mysqli_connect(db_host,db_user,db_password,db_name);

                echo 'TC Number:  '. $tc_number .''; 
                echo 'Property Address:  '. $prop_addr_1. '<br />';  
	        echo '  City:  '. $prop_city. '';
                echo '  State:  '. $prop_state. '';
                echo '  Zip:  '. $prop_zip .'<br />';
                echo '  County:  '. $prop_county . '';
                
     $listing_agent=$_POST['listing_agent'];			
     $listed_realtor=$_POST['listed_realtor'];
     $listing_office=$_POST['listing_office'];
     $sale_sign=$_POST['sale_sign'];
     $sale_sign_comm=$_POST['sale_sign_comm'];
     $vandalism=$_POST['vandalism'];
     $vandalism_comm=$_POST['vandalism_comm'];
     $code_viol=$_POST['code_viol'];
     $code_viol_comm=$_POST['code_viol_comm'];
     $health_safe=$_POST['health_safe'];
     $health_safe_comm=$_POST['health_safe_comm'];
     $prop_secure=$_POST['prop_secure'];
     $prop_secure_comm=$_POST['prop_secure_comm'];
     $land_main=$_POST['land_main'];
     $land_main_comm=$_POST['land_main_comm'];
     $int_clean=$_POST['int_clean'];
     $int_clean_comm=$_POST['int_clean_comm'];
     $electricity=$_POST['electricity'];
     $electricity_comm=$_POST['electricity_comm'];
     $water=$_POST['water'];
     $water_comm=$_POST['water_comm'];
     $winterized=$_POST['winterized'];
     $winterized_comm=$_POST['winterized_comm'];
     $add_comm=$_POST['add_comm'];
     $mls_number=$_POST['mls_number'];
     $mls_location=$_FILES['uploadmls']['name'];
     $curr_price=$_POST['curr_price'];
     $prev_price=$_POST['prev_price'];
     $dt_last_reduc=$_POST['dt_last_reduc'];
   
if(isset($_POST['submit'])){
     //insert new record to prop_insp
     $query_pir_insert="INSERT INTO prop_insp(job_id,listing_agent,listed_realtor,sale_sign,sale_sign_comm,vandalism,vandalism_comm,health_safe,health_safe_comm,prop_secure,prop_secure_comm,land_main,land_main_comm,electricity,electricity_comm,water,water_comm,int_clean,int_clean_comm,winterized,winterized_comm,listing_office,code_viol,code_viol_comm)
VALUES('$job_id','$listing_agent','$listed_realtor','$sale_sign','$sale_sign_comm','$vandalism','$vandalism_comm','$health_safe','$health_safe_comm','$prop_secure','$prop_secure_comm','$land_main','$land_main_comm','$electricity','$electricity_comm','$water','$water_comm','$int_clean','$int_clean_comm','$winterized','$winterized_comm','$listing_office','$code_viol','$code_viol_comm')";
     $result_pir_insert=mysqli_query($dbc,$query_pir_insert) or die('ERROR PIR INSERT');

//update job fields
     $query_job_update="UPDATE job 
                        SET  mls_number='$mls_number',curr_price='$curr_price',prev_price='$prev_price',dt_last_reduc='$dt_last_reduc', mls_location='$mls_location'
                        WHERE job_ID='$job_id'";
     $result_job_update=mysqli_query($dbc,$query_job_update)or die('ERROR JOB UPDATE');
  
mysqli_close($dbc);
}

if(isset($_POST['propinsppdf'])){

$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
}

?>            
<h2><center>PROPERTY INSPECTION FORM</center></h2>
<p><input value="Upload Photos" name="uploadphoto" type="submit" /><input value="Submit Data" name="submit" type="submit" /><input value="Produce PDF" name="propinsppdf" type="submit" /></p>
<table>
<tbody>
<tr>
<th>Listing Agent Name</th>
<td></td>
<td><input name="listing_agent" type="text" /></td>
</tr>
<tr>
<th>Listing Agent Office</th>
<td></td>
<td><input name="listing_office" type="text" /></td>
</tr>
<tr>
<th>Is the property currently listed on MLS?</th>
<td><input name="mls_number" type="text" /></td>
<td><input type="file" id="uploadmls" name="uploadmls" /></td>
</tr>
<tr>
<th>Is the property currently listed on Realtor.com?</th>
<td>Yes<input name="listed_realtor" value="Y" type="radio" /> No<input name="listed_realtor" value="N" type="radio" /></td>
</tr>
<tr>
<th>Current Price: </th>
<td></td>
<td><input name="curr_price" type="currency" /></td>
</tr>
<tr>
<th>Previous Price: </th>
<td></td>
<td><input name="curr_price" type="currency" /></td>
</tr>
<tr>
<th>Date of Last Price Reduction: </th>
<td></td>
<td><input name="dt_last_reduc" type="date" />
<p>&nbsp;</p>
</td>
</tr>
<tr>
<th>Is there a for sale sign visible from the street?</th>
<td>Yes<input name="sale_sign" value="Y" type="radio" /> No<input name="sale_sign" value="N" type="radio" /></td>
<td><textarea name="sale_sign_comm" rows="2" cols="40"></textarea></td>
</tr>
<tr>
<th>Are there any signs of vadalism?</th>
<td>Yes<input name="vandalism" value="Y" type="radio" /> No<input name="vandalism" value="N" type="radio" /></td>
<td><textarea name="vandalism_comm" rows="2" cols="40"></textarea></td>
</tr>
<tr>
<th>Are there any visible signs of code violations?</th>
<td>Yes<input name="code_viol" value="Y" type="radio" /> No<input name="code_viol" value="N" type="radio" /></td>
<td><textarea name="code_viol_comm" rows="2" cols="40"></textarea></td>
</tr>
<tr>
<th>Are there any health and safety issues with the property?</th>
<td>Yes<input name="health_safe" value="Y" type="radio" /> No<input name="health_safe" value="N" type="radio" /></td>
<td><textarea name="health_safe_comm" rows="2" cols="40"></textarea></td>
</tr>
<tr>
<th>Is the property secured?</th>
<td>Yes<input name="prop_secure" value="Y" type="radio" /> No<input name="prop_secure" value="N" type="radio" /></td>
<td><textarea name="prop_secure_comm" rows="2" cols="40"></textarea></td>
</tr>
<tr>
<th>Is the landscaping maintained?</th>
<td>Yes<input name="land_main" value="Y" type="radio" />No<input name="land_main" value="N" type="radio" /></td>
<td><textarea name="land_main_comm" rows="2" cols="40"></textarea></td>
</tr>
<tr>
<th>Is the interior of the property clean?</th>
<td>Yes<input name="int_clean" value="Y" type="radio" /> No<input name="int_clean" value="N" type="radio" /></td>
<td><textarea name="int_clean_comm" rows="2" cols="40"></textarea></td>
</tr>
<tr>
<th>Is the electricity turned on?</th>
<td>Yes<input name="electricity" value="Y" type="radio" /> No<input name="electricity" value="N" type="radio" /></td>
<td><textarea name="electricity_comm" rows="2" cols="40"></textarea></td>
</tr>
<tr>
<th>Is the water turned on?</th>
<td>Yes<input name="water" value="Y" type="radio" /> No<input name="water" value="N" type="radio" /></td>
<td><textarea name="water_comm" rows="2" cols="40"></textarea></td>
</tr>
<tr>
<th>If between September and April, are there notices that the home has been winterized? (please provide photos of notices)?</th>
<td>Yes<input name="winterized" value="Y" type="radio" /> No<input name="winterized" value="N" type="radio" />N/A<input name="winterized" value="na" type="radio" /></td>
<td><textarea name="winterized_comm" rows="2" cols="40"></textarea></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<th>Please provide any additional comments, such as, condition of neighboring homes, current real estate market conditions in the area.</th>
<td><textarea name="add_comm" rows="2" cols="40"></textarea></td>
</tr>
</tbody>
</table>
Agent Name: <input name="agent_name" type="text" /> Date Inspection Completed:  <input name="completed_date" type="date" />
<p>&nbsp;</p>
<p><input value="Upload Photos" name="uploadphoto" type="submit" /><input value="Submit Data" name="submit" type="submit" /><input value="Produce PDF" name="propinsppdf" type="submit" /></p>
</form>
</body>
</html>

Open in new window

rcowen00Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tpraveenrajCommented:
remove this part of echoes, u'll be out of the error
echo 'TC Number:  '. $tc_number .''; 
echo 'Property Address:  '. $prop_addr_1. '<br />';  
echo '  City:  '. $prop_city. '';
echo '  State:  '. $prop_state. '';
echo '  Zip:  '. $prop_zip .'<br />';
echo '  County:  '. $prop_county . '';

Open in new window

Marco GasiFreelancerCommented:
First: you have to delete all echo statements you have inserted in script: you can create a function that use Cell or MultiCell methods and call this function before to call $pdf->Output;
Second: you must to put your pdf script at very top of page: you can use some conditional statement such as
if (isset($_POST['submit']))
             here your script
else
here html
This way doesn't raise any error.

rcowen00Author Commented:
tpraveenraj- just removing the echo's did not get rid of the error.

marqusG-I will give your suggestion a try.  

Thank you both.
rcowen00Author Commented:
margusG- stupid question:  when you say "top of the page" do you mean at the beginning of the php or physically the top of the page?
Marco GasiFreelancerCommented:
Absolutely at the top:

1: <? php script to create pdf doc if submit is in $_POST?>
2: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN http: //www.w3.org/TR/html4 /loose.dtd">
<html>
        <head> and the rest of Html code

This is because nothing must be printed before pdf output
Personally, I prefer write a page with html form and set form action to load a new page wich contains only php script to make pdf doc
Bye

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.