Solved

php inclusion acting differntly between 2 pages.

Posted on 2016-09-08
7
31 Views
Last Modified: 2016-09-08
I created a small inclusion to do the query write/update.  It works in page 1, but when I added the code to page 2, it displays the remarks, all the code and does not perform the update.

I've attached the relevant code for the two pages as well as the inclusion.
page1.php
page2.php
IO_inc.php
0
Comment
Question by:breeze351
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 41790269
It looks like page 2 is not recognized as a php script: is there the php opening tag? In code you posted here that is missing in all files...
1
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 41790314
Agree with Marco.  Please add <?php error_reporting(E_ALL); as the top line of all three scripts, and try it again.  Please let us know if you get different output, or if you get messages that might be associated with these scripts.
0
 

Author Comment

by:breeze351
ID: 41790349
The <?php is at the top of both pages.
I added error_reporting(E_ALL) to the top of page 2.
Got the same results with the display of comments and code.

Just for the halibut, I added <?php ..... ?> to the inclusion.  It processes the code as expected (update worked), however I got the following error message:

Warning: Cannot modify header information - headers already sent by (output started at /home/mrbreez1/public_html/IO_inc.php:25) in /home/mrbreez1/public_html/Update_Tenant.php on line 268

I know what the error means, but the only thing that would cause this is echo statement in the inclusion that isn't executed.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 52

Accepted Solution

by:
Julian Hansen earned 250 total points
ID: 41790385
Try removing the closing ?> on the io_inc.php page

The error is saying that some output was sent. This could be a space that comes after the closing ?>

If the page is all PHP code you can omit the closing ?> which prevents any empty spaces at the end of the script being interpreted as output to the browser
i.e
<?php
// **************************************************************
// * IO_inc.php                                                 *
// * Inclusion to preform SQL I/O with error checking.          *
// **************************************************************
// * Version 4.0                                                *
// **************************************************************
// * Modifications:                                             *
// * Ver   By     Date       Description                        *
// * 4.0   GJJD   09/06/16   Created                            *
// *                                                            *
// ************************************************************** 
	$io = $conn->query($SqlString);			
	if (!$io)
	{
		$io_error = "Query Failed: "
		. $SqlString
		. ' ERRNO: '
		. $conn->errno
		. ' ERROR: '
		. $conn->error
		;
		echo $io_error."<br>";
	}

Open in new window

0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 41790431
Unless it's absolutely necessary, you never want to use the close-PHP tag.  It creates more problems than it's worth.

"Cannot modify header..." is covered here (check the part about output buffering):
https://www.experts-exchange.com/articles/4423/Warning-Cannot-modify-header-information-headers-already-sent.html

It sounds like the issue might be something in the context or scope of the scripts.  I don't think we have enough information here to debug it (without a lucky guess), so if you can tell us a little more about how these scripts get called, or better yet create the SSCCE that we can install and run on our own servers, that would be very helpful.
0
 

Author Closing Comment

by:breeze351
ID: 41790537
I removed the ?> and it worked.  I don't care right now because it does work, but why would it work on page1 and not page2!
0
 
LVL 52

Expert Comment

by:Julian Hansen
ID: 41790720
Without access to the raw files cannot say. The files you posted seemed sanitized - there were no script tags so assuming they are not strictly the same as the live ones.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now