Avatar of Richard Korts
Richard Korts
Flag for United States of America asked on

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

PDFPHP

Avatar of undefined
Last Comment
Richard Korts

8/22/2022 - Mon
Chris Stanyon

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
Richard Korts

ASKER
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

kenfcamp

Try replacing "//" with "#", and see if that makes a difference
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
kenfcamp

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
Terry Woods

How about adding an extra echo, and seeing what happens? :-)
ASKER CERTIFIED SOLUTION
Chris Stanyon

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
lenamtl

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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Richard Korts

ASKER
This has become a LOW priority, some suggestions helped.

I m awarding points on what I think is fair