Can't get rid of echos by commenting out

I have a situation where I use fpdf to generated pdfs. In one specific case, it was generating a BLANK pdf. So I put some echos in (php) so I could start to track where it was going wrong.

As soon as I put the echos in, it worked fine.

FYI, this is NOT the first time this has happened to me (that is, putting echos in & the problem disappears).

Since I don't want the echos in the live environment, I commented them out in the php using //.

Uploaded them to the server (only 2 programs), ran test again, echos still there, process worked.

Cleared the cache (in Firefox), ran the test again, echos still show.

Since they just flash by in a split second, decided to make it live this way since it now works.

Anyone have ANY idea why this crazy business happens like this?

Here is one of the echos, commented out, in the code now:

//if ($_SESSION['form'] == "Pearland" && $_SESSION['user'] == 2) {
	//echo "got to start of switch with Pearland<br>";
//}	

Open in new window

Richard KortsBusiness Owner / Chief DeveloperAsked:
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.

Chris StanyonWebDevCommented:
Hey Richard,

There's nothing fundamentally wrong with that code. Commented out code shouldn't run, but only see a small snippet of your code doesn't give us a lot to go on. Double check the obvious - you've definitely uploaded the right file to the right location (seems silly, I know ... but it happens!)

Check you've got your opening and closing PHP tags coded properly (don't use shorttags).

If you're still stuck, post up your code so we can take a proper look
0
Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
Here is the full code of that program:
<?php
error_reporting(E_ERROR);
date_default_timezone_set("America/Chicago");
function conv_date($x) {
		$d = explode("-", $x);
		$r = $d[1] . "/" . $d[2] . "/" . $d[0];
		return $r;
	}
function conv_date_yy($x) {
		$r = substr($x,0,6) . substr($x,8,2);
		return $r;
	}
function conv_qt($x) {
	$r = str_replace('&#34;', '"', $x);
	return $r;
}
function trans_quote($x) {
	$r = str_replace("&#39;", "'", $x);
	return $r;
}
session_start();	
$pta = $_GET['pta'];
if(! empty($_SERVER['HTTP_USER_AGENT'])){
		$useragent = $_SERVER['HTTP_USER_AGENT'];
		if( preg_match('@(iPad|iPod|iPhone|Android|BlackBerry|SymbianOS|SCH-M\d+|Opera Mini|Windows CE|Nokia|SonyEricsson|webOS|PalmOS)@', $useragent) ){
			$dest = "phone.php";
		} else {
			$dest = "form.php";
	}
} 
// hard code fix for Brammer
if ($_SESSION['user'] == 30 ){
	$_SESSION['bftno'] = "BP0012317";
}	
//echo "get ems = " . $_GET['ems'] . "<br>";
$fr = $_GET['fr'];
include "db_connect.php";
include "get_loc.php";
require_once('fpdf.php');
//echo "firm addr2 = " . $_SESSION['bfaddr2'] . "<br>";
//$ad2 = explode(" ", $_SESSION['bfaddr2']);
//echo "zip = " . $ad2[2] . "<br>";
//echo "ptype = " . $_SESSION['ptype'] . "<br>";
//echo "lic exp date = " . $_SESSION['lexpdate'] . "<br>";
$property = $_SESSION['padr'] . " " . $_SESSION['city'] . " " . $_SESSION['zip'];
//echo $_SESSION['rmurv'] . "<br>";
//echo $_SESSION['keymap2'] . "<br>";
include "conv_to_quote.php";
$pdf=new FPDF('P', 'pt', 'Letter');
$pdf->SetAutoPageBreak(false);
$pdf->SetDisplayMode('real');
$pdf->SetTopMargin(2);
$pdf->SetleftMargin(10);
// include form based on $_SESSION['form']
//if ($_SESSION['user'] == 2) {
	//echo "form = " . $_SESSION['form'] . "<br>";
//}	
//if ($_SESSION['user'] == 2) {
	//echo "session[form] = " . $_SESSION['form'] . "<br>";
//}	
//if ($_SESSION['form'] == "Pearland" && $_SESSION['user'] == 2) {
	//echo "got to start of switch with Pearland<br>";
//}	
if ($_SESSION['form'] == "" || $_SESSION['form'] == "Houston") {
	include "gen_pdf_houston_new.php";
} else {
	switch ($_SESSION['form']) {
		case "Tomball":
			include "gen_pdf_Tomball.php";
			break;	
		case "Conroe":
			include "gen_pdf_Conroe.php";
			break;
		case "Sugar Land":
			include "gen_pdf_sugarland.php";
			break;
		case "The Woodlands":
			include "gen_pdf_woodlands.php";
			break;	
		case "Richmond":
			include "gen_pdf_richmond.php";
			break;	
		case "Friendswood":
			include "gen_pdf_friendswood.php";
			break;	
		case "Alvin":
			include "gen_pdf_alvin.php";
			break;		
		case "Fulshear":
			include "gen_pdf_fulshear.php";
			break;	
		case "Katy":
			include "gen_pdf_katy.php";
			break;	
		case "Fort Bend Utility - WCT#2":
			include "gen_pdf_fort_bend.php";
			break;	
		case "College Station":
			include "gen_pdf_college_station.php";
			break;
		case "Deer Park":
			include "gen_pdf_deer_park.php";
			break;
		case "Galveston":
			include "gen_pdf_galveston.php";
			break;	
		case "West University Place":
			include "gen_pdf_west_univ_place.php";
			break;	
		case "Baytown":
			//echo "finalpass = " . $_SESSION['finalpass'];
			include "gen_pdf_baytown.php";
			break;		
		case "Rosenberg":
			include "gen_pdf_rosenberg.php";
			break;		
		case "Humble":
			include "gen_pdf_humble.php";
			break;	
		case "Oak Ridge North":
			include "gen_pdf_oak_ridge_north.php";
			break;	
		case "Bellaire":
			include "gen_pdf_bellaire.php";
			break;	
		case "Shenandoah":	
			include "gen_pdf_shenandoah.php";
			break;
		case "San Antonio":	
			include "gen_pdf_sanantonio.php";
			break;	
		case "Manvel":	
			include "gen_pdf_manvel.php";
			break;	
		case "Texas City":	
			include "gen_pdf_texas_city.php";
			break;	
		case "MUD - Katy Builder Services":	
			include "gen_pdf_muni_dist_svcs.php";
			break;	
		case "Bunker Hill Village":	
			include "gen_pdf_bunker_hill.php";
			break;	
		case "Jersey Village":	
			include "gen_pdf_jersey_village.php";
			break;	
		case "TCEQ":	
			include "gen_pdf_TCEQ_new.php";	
			break;		
		case "League City":
			include "gen_pdf_league_city.php";
			break;	
		case "Memorial Villages":
			include "gen_pdf_memorial_villages.php";
			break;
		case "La Porte":
			include "gen_pdf_laporte_new.php";
			break;
		case "Corpus Christi":
			include "gen_pdf_corpus_christi.php";
			break;	
		case "Port Aransas":
			include "gen_pdf_port_aransas.php";
			break;		
		case "Dallas":
			include "gen_pdf_Dallas.php";
			break;
		case "Ft. Worth":
			include "gen_pdf_ftworth.php";
			break;	
		case "Spring":
			include "gen_pdf_spring.php";
			break;	
		case "Pearland":
			include "gen_pdf_Pearland_TCEQ.php";
			break;	
		case "Pasadena":
			include "gen_pdf_pasadena_newest.php";
			break;	
	}
}	
//echo "qry = " . $qryct . "<br>";
// THE END!!
$fname = "forms/" . $_SESSION['pn'] . ".pdf";
if ($_SESSION['blank']) {
	$fname = "forms/" . $_SESSION['user'] . "blank" . $_SESSION['form'] . ".pdf";
}	
//echo "fname = " . $fname . "<br>";
$pdf->Output($fname, "F");
// see if email form to admins (if any)
$qrya = "SELECT * from firm_admins where uid = " . $_SESSION['user'];
$resa = mysqli_query($link, $qrya);
$na = mysqli_num_rows($resa);
if ($_SESSION['user'] == 2) {
	//echo "sta = " . $_GET['sta'] . "<br>";
	//echo "session[pta] = " . $_SESSION['pta'] . "<br>";
}
if ($na != 0) {
	if ($pta == "Y" || $_GET['sta'] == "on") {
	    require_once('class.phpmailer.php');

		$mail             = new PHPMailer(); // defaults to using php "mail()"


		$mail->isSMTP(); // telling the class to use SMTP transport
 

		$body             = "";
 

		$mail->SetFrom('noreply@backflowtestreport.com');

		$mail->SMTPSecure = $GLOBALS['smtp_security'];

		$mail->Port       = $GLOBALS['smtp_port'];

		$mail->Subject   = "Completed form for " . $_SESSION['pn'] . " - " . $_SESSION['padr'];

		$body = "Attached is a completed backflow test report form for your information";
	    	for ($i = 0; $i < $na; $i++) {
			$ad = mysqli_fetch_array($resa,MYSQLI_ASSOC);
			$mail->AddAddress($ad['email']);

		}
		$mail->AddAttachment($fname);

		$mail->AltBody = strip_tags($body);

		$mail->MsgHTML($body);

		if ($_SESSION['user'] == 2) {
			if(!$mail->Send()) {
	echo "Mailer Error: " . $mail->ErrorInfo;
}
		} else {
			$mail->Send();
		}
	}
}
?>
<!DOCTYPE html>

<html>
<head>
<title>Print Single Form</title>
<meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css">

    <title>Backflow Assembly & Test Report Form</title>
    <style>
        .nopadding {
            padding: 0 !important;
            margin: 0 !important;
        }
        
        .wrapper {
            max-width: 767px;
            min-width: 480px;
            margin: 0 auto;
        }
    </style>
	<script>
	user = <? print $_SESSION['user']; ?>;
	fname = "<? print $fname; ?>";
	ac = "";
	fr = "<? print $fr; ?>";
	ems = "<? print $_GET['ems']; ?>";
	loc = "<? print $loc; ?>";
	function open_pdf_win() {
		str = loc + fname;	
		window.open(str);
	}
	function ask_email() {
		jj = confirm("Email printed form to my email?");
		if (jj) {
			window.location = "email_pdf.php?f=" + fname;
		}
		window.location = "print_cleanup.php?fr=" + fr + "&ems=Y";
	}
	</script>
</head>
	<body onLoad="open_pdf_win(); ask_email();"> 
	<? if ($_GET['ems'] != "y") {?>
		<body onLoad="ask_email();">
	<? } ?>	
</body>
</html>

Open in new window

0
kenfcampCommented:
Try replacing "//" with "#", and see if that makes a difference
0
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

kenfcampCommented:
Try this, let us know how you make out

<?php
error_reporting(E_ERROR);
date_default_timezone_set("America/Chicago");
function conv_date($x) {
		$d = explode("-", $x);
		$r = $d[1] . "/" . $d[2] . "/" . $d[0];
		return $r;
	}
function conv_date_yy($x) {
		$r = substr($x,0,6) . substr($x,8,2);
		return $r;
	}
function conv_qt($x) {
	$r = str_replace('&#34;', '"', $x);
	return $r;
}
function trans_quote($x) {
	$r = str_replace("&#39;", "'", $x);
	return $r;
}
session_start();	
$pta = $_GET['pta'];
if(! empty($_SERVER['HTTP_USER_AGENT'])){
		$useragent = $_SERVER['HTTP_USER_AGENT'];
		if( preg_match('@(iPad|iPod|iPhone|Android|BlackBerry|SymbianOS|SCH-M\d+|Opera Mini|Windows CE|Nokia|SonyEricsson|webOS|PalmOS)@', $useragent) ){
			$dest = "phone.php";
		} else {
			$dest = "form.php";
	}
} 
// hard code fix for Brammer
if ($_SESSION['user'] == 30 ){
	$_SESSION['bftno'] = "BP0012317";
}	
		# echo "get ems = " . $_GET['ems'] . "<br>";
$fr = $_GET['fr'];
include "db_connect.php";
include "get_loc.php";
require_once('fpdf.php');
	/*
		echo "firm addr2 = " . $_SESSION['bfaddr2'] . "<br>";
		$ad2 = explode(" ", $_SESSION['bfaddr2']);
		echo "zip = " . $ad2[2] . "<br>";
		echo "ptype = " . $_SESSION['ptype'] . "<br>";
		echo "lic exp date = " . $_SESSION['lexpdate'] . "<br>";
	*/
$property = $_SESSION['padr'] . " " . $_SESSION['city'] . " " . $_SESSION['zip'];
	/*
		echo $_SESSION['rmurv'] . "<br>";
		echo $_SESSION['keymap2'] . "<br>";
	*/
include "conv_to_quote.php";
$pdf=new FPDF('P', 'pt', 'Letter');
$pdf->SetAutoPageBreak(false);
$pdf->SetDisplayMode('real');
$pdf->SetTopMargin(2);
$pdf->SetleftMargin(10);
	/*
		include form based on $_SESSION['form']
		if ($_SESSION['user'] == 2) {
		echo "form = " . $_SESSION['form'] . "<br>";
		}	
		if ($_SESSION['user'] == 2) {
		echo "session[form] = " . $_SESSION['form'] . "<br>";
		}	
		if ($_SESSION['form'] == "Pearland" && $_SESSION['user'] == 2) {
		echo "got to start of switch with Pearland<br>";
		}	
	*/
if ($_SESSION['form'] == "" || $_SESSION['form'] == "Houston") {
	include "gen_pdf_houston_new.php";
} else {
	switch ($_SESSION['form']) {
		case "Tomball":
			include "gen_pdf_Tomball.php";
			break;	
		case "Conroe":
			include "gen_pdf_Conroe.php";
			break;
		case "Sugar Land":
			include "gen_pdf_sugarland.php";
			break;
		case "The Woodlands":
			include "gen_pdf_woodlands.php";
			break;	
		case "Richmond":
			include "gen_pdf_richmond.php";
			break;	
		case "Friendswood":
			include "gen_pdf_friendswood.php";
			break;	
		case "Alvin":
			include "gen_pdf_alvin.php";
			break;		
		case "Fulshear":
			include "gen_pdf_fulshear.php";
			break;	
		case "Katy":
			include "gen_pdf_katy.php";
			break;	
		case "Fort Bend Utility - WCT#2":
			include "gen_pdf_fort_bend.php";
			break;	
		case "College Station":
			include "gen_pdf_college_station.php";
			break;
		case "Deer Park":
			include "gen_pdf_deer_park.php";
			break;
		case "Galveston":
			include "gen_pdf_galveston.php";
			break;	
		case "West University Place":
			include "gen_pdf_west_univ_place.php";
			break;	
		case "Baytown":
		  # echo "finalpass = " . $_SESSION['finalpass'];
			include "gen_pdf_baytown.php";
			break;		
		case "Rosenberg":
			include "gen_pdf_rosenberg.php";
			break;		
		case "Humble":
			include "gen_pdf_humble.php";
			break;	
		case "Oak Ridge North":
			include "gen_pdf_oak_ridge_north.php";
			break;	
		case "Bellaire":
			include "gen_pdf_bellaire.php";
			break;	
		case "Shenandoah":	
			include "gen_pdf_shenandoah.php";
			break;
		case "San Antonio":	
			include "gen_pdf_sanantonio.php";
			break;	
		case "Manvel":	
			include "gen_pdf_manvel.php";
			break;	
		case "Texas City":	
			include "gen_pdf_texas_city.php";
			break;	
		case "MUD - Katy Builder Services":	
			include "gen_pdf_muni_dist_svcs.php";
			break;	
		case "Bunker Hill Village":	
			include "gen_pdf_bunker_hill.php";
			break;	
		case "Jersey Village":	
			include "gen_pdf_jersey_village.php";
			break;	
		case "TCEQ":	
			include "gen_pdf_TCEQ_new.php";	
			break;		
		case "League City":
			include "gen_pdf_league_city.php";
			break;	
		case "Memorial Villages":
			include "gen_pdf_memorial_villages.php";
			break;
		case "La Porte":
			include "gen_pdf_laporte_new.php";
			break;
		case "Corpus Christi":
			include "gen_pdf_corpus_christi.php";
			break;	
		case "Port Aransas":
			include "gen_pdf_port_aransas.php";
			break;		
		case "Dallas":
			include "gen_pdf_Dallas.php";
			break;
		case "Ft. Worth":
			include "gen_pdf_ftworth.php";
			break;	
		case "Spring":
			include "gen_pdf_spring.php";
			break;	
		case "Pearland":
			include "gen_pdf_Pearland_TCEQ.php";
			break;	
		case "Pasadena":
			include "gen_pdf_pasadena_newest.php";
			break;	
	}
}	
		# echo "qry = " . $qryct . "<br>";
// THE END!!
$fname = "forms/" . $_SESSION['pn'] . ".pdf";
if ($_SESSION['blank']) {
	$fname = "forms/" . $_SESSION['user'] . "blank" . $_SESSION['form'] . ".pdf";
}	
		# echo "fname = " . $fname . "<br>";
$pdf->Output($fname, "F");
// see if email form to admins (if any)
$qrya = "SELECT * from firm_admins where uid = " . $_SESSION['user'];
$resa = mysqli_query($link, $qrya);
$na = mysqli_num_rows($resa);
if ($_SESSION['user'] == 2) {
	/*
		echo "sta = " . $_GET['sta'] . "<br>";
		echo "session[pta] = " . $_SESSION['pta'] . "<br>";
	*/
}
if ($na != 0) {
	if ($pta == "Y" || $_GET['sta'] == "on") {
	    require_once('class.phpmailer.php');

		$mail             = new PHPMailer(); // defaults to using php "mail()"


		$mail->isSMTP(); // telling the class to use SMTP transport
 

		$body             = "";
 

		$mail->SetFrom('noreply@backflowtestreport.com');

		$mail->SMTPSecure = $GLOBALS['smtp_security'];

		$mail->Port       = $GLOBALS['smtp_port'];

		$mail->Subject   = "Completed form for " . $_SESSION['pn'] . " - " . $_SESSION['padr'];

		$body = "Attached is a completed backflow test report form for your information";
	    	for ($i = 0; $i < $na; $i++) {
			$ad = mysqli_fetch_array($resa,MYSQLI_ASSOC);
			$mail->AddAddress($ad['email']);

		}
		$mail->AddAttachment($fname);

		$mail->AltBody = strip_tags($body);

		$mail->MsgHTML($body);

		if ($_SESSION['user'] == 2) {
			if(!$mail->Send()) {
	echo "Mailer Error: " . $mail->ErrorInfo;
}
		} else {
			$mail->Send();
		}
	}
}
?>
<!DOCTYPE html>

<html>
<head>
<title>Print Single Form</title>
<meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css">

    <title>Backflow Assembly & Test Report Form</title>
    <style>
        .nopadding {
            padding: 0 !important;
            margin: 0 !important;
        }
        
        .wrapper {
            max-width: 767px;
            min-width: 480px;
            margin: 0 auto;
        }
    </style>
	<script>
	user = <? print $_SESSION['user']; ?>;
	fname = "<? print $fname; ?>";
	ac = "";
	fr = "<? print $fr; ?>";
	ems = "<? print $_GET['ems']; ?>";
	loc = "<? print $loc; ?>";
	function open_pdf_win() {
		str = loc + fname;	
		window.open(str);
	}
	function ask_email() {
		jj = confirm("Email printed form to my email?");
		if (jj) {
			window.location = "email_pdf.php?f=" + fname;
		}
		window.location = "print_cleanup.php?fr=" + fr + "&ems=Y";
	}
	</script>
</head>
	<body onLoad="open_pdf_win(); ask_email();"> 
	<? if ($_GET['ems'] != "y") {?>
		<body onLoad="ask_email();">
	<? } ?>	
</body>
</html>

Open in new window


Ken
0
Terry WoodsIT GuruCommented:
How about adding an extra echo, and seeing what happens? :-)
0
Chris StanyonWebDevCommented:
Hi Richard,

I can't see anything obviously wrong with your code, but having said that there are a few areas that could cause you problems or unwanted side-effects (not checking variables for null etc).

To get to the bottom of it, I would start debugging the probem by simplifying your code and then building it up step by step. Start by turning on full error reporting:

error_reporting(E_ALL);
ini_set('display_errors', 1);

Then I would strip out all the email and javascript bits and instead just output the PDF to the browser. Change line 189 to the following:

$pdf->Output("I", $fname);

(Currently in your code you have the 2 arguments the other way around - $pdf->Output($fname, "F") - looking at the Docs, this is wrong, but I don't know if you're using an old version of FPDF!)

and then remove everything after line 189.

I would also remove all the echo lines completely. If you want to see what's going on, it's generally cleaner to write info to the log file rather than echo out to the browser. You can do that with the error_log command:

error_log("Some Message");

I'm not saying this will fix your error but it will help you debug it.
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
lenamtlCommented:
Hi,

Check in PHP logs you probably have an error on your page that mess the code.
If you are using wampserver logs are located in C:\wamp64\logs
0
Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
This has become a LOW priority, some suggestions helped.

I m awarding points on what I think is fair
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
PDF

From novice to tech pro — start learning today.