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.
rcowen00Asked:
Who is Participating?
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.

rcowen00Author Commented:
I'm sorry, I just realized I didn't enter the code.  Here it is
<!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

0
subscriptCommented:
I have not used FPDF yet myself but it looks like you might be submitting a form to the same page...
that you've already output HTML to.

I personally prefer breaking up with process by using a second php action/processing type page...
and that second page is where you put all your php form handling stuff, fpdf, etc -- where everything is within <?php  ?>.

Then when finished processing -- send the user back to the original page (or a third page if you prefer) to show results.

Option 2... would be to do what you're doing but make sure that the first thing you do on the page is your <?php ?> script that checks for the submitted vars and attempts to process them if found.

Note: Make sure there's no other spaces, HTML etc on the page above that initial <?php  ?> block.

Try it and let me know if that didn't fix your issue.

0
Ray PaseurCommented:
The header issue is caused by ANY browser output at all, so the very first line with the DOCTYPE declaration is the start of the problem - it is browser output.  In other words, the script is misdesigned if you intend to send headers.

My recommendation: Write the PDF to a file and give the client a link to access it.  That way you will not have to rewrite your application - just make a few changes.  HTH, ~Ray
0

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
rcowen00Author Commented:
Thank you
0
Ray PaseurCommented:
Thanks for the points - it's a great question! ~Ray
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.