Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

Seeming issue with php

I have some changes I made to an existing program. It's php, it shows the lovely blank screen. I looked at the source (from view source in Firefox), this code is the VERY last code in the source:
				<div class="row">
			<div class="col-sm-7 col-xs-7" style="font-size:16px;padding-bottom:5px;padding-left:20px;">Grooved Coupling Spools</div>
			<div class="col-sm-5 col-xs-5 text-right" style="font-size:16px;padding-bottom:5px;">$352.00</div>
		</div>
			
				
																		<div class="row" style="padding-top:5px;">
			<div class="col-sm-7 col-xs-7" style="font-size:18px;padding-bottom:10px;"><b>Total Markup Price</b></div>
			<div class="col-sm-5 col-xs-5 text-right" style="font-size:16px;padding-bottom:10px;"><b>$15,163.00</b></div>
		</div>

Open in new window


My guess is nothing displays because there are at least two unclosed <div>'s and there is no </body> or </html>.

The php source, right after the view code stuff (just a few lines) looks like this:

<div class="row" style="padding-top:5px;">
			<div class="col-sm-7 col-xs-7" style="font-size:18px;padding-bottom:10px;"><b>Total Markup Price</b></div>
			<div class="col-sm-5 col-xs-5 text-right" style="font-size:16px;padding-bottom:10px;"><b>$<? print number_format($ptot,2); ?></b></div>
		</div>
		<? // build markup pdf
		include "pdf_summary_markup.php"; ?>
		<? } ?>
	<? // Net Pricing
		if ($net_pricing) { 

Open in new window


So I suspected pdf_summary_markup.php.

|I have run it through http://phpcodechecker.com/. It finds no issues. The outer calling program (the one with includes "pdf_summary_markup.php" has an error_reporting(E_ALL); as the very first line.

I can show the entire code from pdf_summary_markup.php, it's kind of long. It basically builds a pdf document using fpdf.

I'm looking for suggestions as to how I can find the cause of the error.

Thanks
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Open up pdf_summary_markup.php and take this line:
echo __LINE__ . "\n";

Open in new window


...and add it throughout the code inside pdf_summary_markup.php. For example, old code:
<?php
// pdf_summary_markup.php
$pdf = new PDF();
addContentToThePDF($pdf);
doSomeOtherStuff($pdf);
renderThePDF($pdf);

Open in new window


Adjusted code:
<?php
// pdf_summary_markup.php
echo __LINE__ . "\n";
$pdf = new PDF();
echo __LINE__ . "\n";
addContentToThePDF($pdf);
echo __LINE__ . "\n";
doSomeOtherStuff($pdf);
echo __LINE__ . "\n";
renderThePDF($pdf);
echo __LINE__ . "\n";

Open in new window


Then save and refresh the screen and view the source and see what the last line of code was.
There should be something displayed - even if the tags are not matched.

Usually a blank screen in PHP means there was an error and errors are disabled so nothing is showing. But that would mean that you would get nothing in the view source.

Have you checked the console?

F12 then dig into the document from the body down in the inspector window - until you get to the code you posted above.

From there hover over the various elements and see if they highlight on the screen.

Check the CSS window to see if the elements are being affected by CSS settings.
Avatar of Richard Korts

ASKER

Julian, you mean using Chrome?

Thanks
Hey Richard,

I think I've mentioned this before, but when debugging there are 2 parts to error reporting - one part is to turn error reporting on, and the second part is to display those errors. Without the second part, errors will be written to a log file, but not shown on screen - they've effectively be swallowed - this is what you want in production, but not in development. Make sure you fully turn on error reporting with the following:

error_reporting(E_ALL); // turn on error reporting
ini_set('display_errors', 1); // make sure errors are shown

Open in new window


Run that and then see if any errors are displayed (file not found etc)
Julian, you mean using Chrome?
Or FireFox - both are similar in their console functionality.
Chris,

Yeah, you have. I will try that.

Richard
Chris,

I tried ini_set('display_errors', 1); // make sure errors are shown, it shows a ton of Warnings & Notices, NONE of them from the include where it seems to die. I ran the old (working) version with display-errors, exactly (I think) the same result. I took the display out of the old version & it works perfectly. The two results with display error are attached, "new" being the one with the problem.

Richard
Errors_old_summary.docx
Errors_new_summary.docx
SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To gr8gonzo,

yes, I see that,it is good to know, I will fix that, but it does NOT address the current issue.

I'm going to try a variation (with echos) on your earlier suggestion. See if it even gets into that code & if so, how far.

Richard
Hey Richard,

Looks like you're going to have to take a logical approach to this. If you remove the include entirely, do you get the rest of the page rendered (i.e. all the way to the closing </html>).

If you do, then it's clearly a problem with the include. If you don't then it's unlikely to be a problem with the include.

Try a require instead of an include:

require "pdf_summary_markup.php";

It will still try to include it, but generate a fatal error if it can't.

You'll then need to start stepping through your included file, dropping in various debug methods (echo / var_dump etc). Make sure errors are turned on and displayed in the included file.

If you want to post up your pages, we can take a look over them to see if there's anything obvious.
Warning: include(get_drawing.php): failed to open stream: No such file or directory in /home/lakosind/public_html/summary.php on line 60
This looks like a path issue - your script is not finding files that it needs. The errors on line 9 and 10 might be related to a similar thing.

This code you say was working - it is unlikely that a small change would have introduced so many errors - so what I suspect happened is that the context of the script changed and now resources that previously were loading ok are no longer accessible which is causing the errors.

Can we start by looking at the summary.php script.
To all,

(1) I added an echo in pdf at almost the very beginning of the included pdf_summary_markup.php:
<?php
date_default_timezone_set("America/Los_Angeles");
echo "got into pdf_markup<br>";

Open in new window


It does not display.

(2) I tried to use Chrome to get the console. See attached. The code it is referring to is this:
	function set_pointers() {
		if(document.getElementById("snptxt")) {
			document.getElementById("snptxt").style.cursor = "pointer";
		}
		if(document.getElementById("drawtxt")) {		
			document.getElementById("drawtxt").style.cursor = "pointer";
		}
		if(document.getElementById("swptxt")) {	
			document.getElementById("swptxt").style.cursor = "pointer";
		}
		document.getElementById("iomtxt").style.cursor = "pointer";
		if(document.getElementById("spectxt")) {
			document.getElementById("spectxt").style.cursor = "pointer";
		}
		if(document.getElementById("broctxt")) {	
			document.getElementById("broctxt").style.cursor = "pointer";
		}	
	}

Open in new window


This is referenced here:

<body onLoad="save_proj(); chk_ems(); set_pointers();">

I presumed the error message (in Chrome) means it thinks one of the elements in style.cursor="pointer" does not exist in the document. I checked ALL of them, they are ALL there.

Don't know what do do next. I assume the numbers in the console errors mean the line number in the source. I have now way of knowing how to view source (like you can in FireFox) in Chrome.

Suggestions appreciated.

Oh, & I added an echo in the main program just before the include. It DOES show in view source in Firefox. Both Firefox & Chrome give a blank page initially.
chrome_errors.JPG
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I tried to avoid sending the files, especially summary.php because it is so big, but here you go. Note I am using summaryt.php so it does not effect others testing this; they get the version that works.

Note include pdf_summary_markup is on line 1281 of summaryt.php

Thanks
summaryt.php
pdf_summary_markup.php
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Julian,

Thanks.

I do not know how to view source in Chrome. I can do it in Firefox, I am not sure the line numbers are the same.

I know about the file get_drawing.php, I just have ignored it so far, it's just a matter cof copying that php file from another app it is used in and (maybe) making changes.

I definitely see the error with $_SESSION['project'], there is NO project in this case, I will change to get around that, like you said with isset.

The included programs includer has session_start() almost at the very top.

Thanks,

Richard
Julian,  I found where the error is, I found line 489 in the rendered source, with the vars set the way I have them, it does not exist.

It's kind of complex, but I go off to another program when a markup is confirmed, then I come BACK to summaryt.php. The error on 489 does NOT occur on the first pass, I don't see why, it should occur every time. I think I'll just build a function in summaryt,php that does what I need & have it run that so I don't have to leave.

Richard
To all,

I think I see a solution. I will use an ajax method to write a record to a new database table (every site visitor has a unique ID generated at login).

It's been so long since I did ajax, I can't remember the details about how you reference it from Javascript. I will use php to write the server script.

Can you show me a simple example. I don't want to have to go thru ajax 101 again.

Thanks.
Your jQuery library (if not included - or get from your preferred CDN)
<script src="http://code.jquery.com/jquery.js">

Open in new window

Option 1
$.post
var url = 'http://path/to/your/endpoint/';
var data = $('form').serialize(); // or $(this).serialize in a submit handler
// OR data = {your:"custom",data"'here"}
$.post(url, data, function(resp) {
   // process response here
});
// or if you are expecting a JSON return
$.post(url, data, function(resp) {
   // process response here
}, 'JSON');

Open in new window

Option 2
$.ajax
var url = 'http://path/to/your/endpoint/';
var data = $('form').serialize(); // or $(this).serialize in a submit handler
// OR data = {your:"custom",data"'here"}
$.ajax({
  url:url,
  data:data,
  type: 'POST',
  dataType: 'JSON' // If expecting JSON return
 }).then(function(resp) {
   // process response here
});

Open in new window

If you are doing a GET then it is the same - just replace the POST with GET in the various instances.

Key thing with AJAX is it is async so you only want to start dealing with returned data in the call back - not immediately after the AJAX call.
I'm closing this because it's getting to complex. I'm awarding points based on effort. The REAL way I should look at this is to show you the problem I am trying to solved & get you solution ideas. Look for it in a few minutes. I will categorize it under php, javascript & Jquery.

Thanks for your efforts,

Richard