473,472 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Include Problem

Ken
Hello:

I'm writing my first php app and I have a problem.
Initially I put template type strings, such as HTML Headers and page
footers in a MySQL table and called them up with a php SQL query to
include them in the printed HTML, This worked great but then I learned
about includes and I tried using includes to put them into the HTML.

1. I assume that this is faster than the query method because that's
what people seem to do. Am I right about that?

2. The following string works as a query result but not as an include
file. Could someone be so kind as to explain to me why?

<?xml version="1.0" encoding="UTF-8"\x3f>

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

The parser chokes on the first line. If I remove it the include works
fine.

Thanks,

Ken
Jul 17 '05 #1
5 1814
.oO(Ken)
I'm writing my first php app and I have a problem.
Initially I put template type strings, such as HTML Headers and page
footers in a MySQL table and called them up with a php SQL query to
include them in the printed HTML, This worked great but then I learned
about includes and I tried using includes to put them into the HTML.

1. I assume that this is faster than the query method because that's
what people seem to do. Am I right about that?
I guess so. A filesystem access should be faster than a server request.
2. The following string works as a query result but not as an include
file. Could someone be so kind as to explain to me why?

<?xml version="1.0" encoding="UTF-8"\x3f>
[...]

The parser chokes on the first line. If I remove it the include works
fine.


You have short_open_tags enabled in your php.ini, so the parser treats
the first two chars of <?xml as the beginning of new PHP block, which
causes a parse error. Three solutions:

1) Disable short_open_tags in your php.ini.
2) Use PHP and a print or echo statement to print out the XML prolog:

<?php print "<?xml version='1.0' ...?>";?>

3) Simply remove the prolog. You only need it if you want to use another
encoding than UTF-8 (used by default) and no encoding information was
given in another protocol level, for example in the HTTP response
header.

HTH
Micha
Jul 17 '05 #2
Ken
On Sat, 18 Sep 2004 19:56:59 +0200, Michael Fesser <ne*****@gmx.net>
wrote:
2. The following string works as a query result but not as an include
file. Could someone be so kind as to explain to me why?

<?xml version="1.0" encoding="UTF-8"\x3f>
[...]


You have short_open_tags enabled in your php.ini, so the parser treats
the first two chars of <?xml as the beginning of new PHP block, which
causes a parse error. Three solutions:

1) Disable short_open_tags in your php.ini.
2) Use PHP and a print or echo statement to print out the XML prolog:

<?php print "<?xml version='1.0' ...?>";?>

3) Simply remove the prolog. You only need it if you want to use another
encoding than UTF-8 (used by default) and no encoding information was
given in another protocol level, for example in the HTTP response
header.


Michael,

Thank you very much for your reply and explanation.

Is it odd that it works as a query result?

Ken
Jul 17 '05 #3
Ken wrote:
Hello:

I'm writing my first php app and I have a problem.
Initially I put template type strings, such as HTML Headers and page
footers in a MySQL table and called them up with a php SQL query to
include them in the printed HTML, This worked great but then I learned
about includes and I tried using includes to put them into the HTML.


Why don't you try something like this:

class Whatever {
function Whatever() {
...
}

function output() {
echo "<!DOCTYPE ...";
echo "<html>";
output_header();
output_body();
echo "</html>";
}

function output_head() {
// output common header
...
}

function ouput_body() {
// output custom content
...
}
}

and then for every page you have

$whatever = new Whatever();
$whatever->output();

you can pass parameters to the constructor and then use them to further
customize the body output (say, maybe a page id, which determines what
include file contains the body) :)

Lüph
Jul 17 '05 #4
.oO(Ken)
Is it odd that it works as a query result?


No, because to print out a query result you already use a print or echo
statement, i.e. you are inside a PHP-block. No problem with that. In
your example you try to write it out directly in a HTML-block without
PHP, but PHP interprets it wrong, hence the parse error.

Micha
Jul 17 '05 #5
Ken
On Mon, 20 Sep 2004 01:04:55 +0200, Michael Fesser <ne*****@gmx.net>
wrote:
.oO(Ken)
Is it odd that it works as a query result?


No, because to print out a query result you already use a print or echo
statement, i.e. you are inside a PHP-block. No problem with that. In
your example you try to write it out directly in a HTML-block without
PHP, but PHP interprets it wrong, hence the parse error.


Micha

Please bear with me while I try to grasp this. My include statement
is inside a php block as far as I can see:

<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo "Access to ITR Billing canceled";
exit;
}
else {
$userName = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];

/* Connecting, selecting database */
$link = mysql_connect("localhost", $userName, $password)
or die("Could not connect : " . mysql_error());
mysql_select_db("ITRBilling") or die("Could not select database");

/* Performing SQL querys */
$query2 = "SELECT userName FROM Users WHERE `userName` = \"$userName\"
AND `password` = \"$password\"" ;
$result2 = mysql_query($query2) or die("Query failed : " .
mysql_error());

/* HTML Header */
include("HTMLHeader.txt")
include("PageHeader.txt");

etc...

}
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Yannick Turgeon | last post by:
Oups! I did a typing error in my last post. Fixed. ----------- Hello all, We are currently changing our web server and, in the process, updating PHP version from 4.3.0 to 4.3.5. The problem...
43
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is...
6
by: alan | last post by:
Dear all, I have written my own function by C. And my development platform is W2k with VC6.0. Then I also defined a header file to extern declare this function. After that, I include this...
6
by: atv | last post by:
Alright, i have some questions concerning include files en global variables.I hope someone is willing to answer these. 1).Why is it that if i define a global variable in a file, say main.c, and...
60
by: Derrick Coetzee | last post by:
It seems like, in every C source file I've ever seen, there has been a very definite include order, as follows: - include system headers - include application headers - include the header...
5
by: David Mathog | last post by:
One thing that can make porting C code from one platform to another miserable is #include. In particular, the need to either place the path to an included file within the #include statement or to...
0
by: Francois | last post by:
Hi, I think I found a bug with VS, and I've included a project example of the problem I got. I've got a project deep into a set of folders. The project have an additional include library...
3
by: Arpi Jakab | last post by:
I have a main project that depends on projects A and B. The main project's additional include directories list is: ...\ProjectA\Dist\Include ...\ProjectB\Dist\Include Each of the include...
6
by: tshad | last post by:
In my User control, I tried to do this: *************************************************************************** <Script runat="server"> Public ClientName As String = "<!-- #include file =...
5
by: Tio | last post by:
I have project in MFC(vc++) . There are files and classes: classes:dialog1,dialog2,aaa,bbb ---------------------- main.cpp --------------------- #include "mainfrm.h" #include "dialog1.h"...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.