Jump to content

html working with php


woodsonoversoul

Recommended Posts

Hi all,

A few months ago I started writing a site in all php just to make sure I could get it to work the way I wanted. Once everything was working I started to get things looking like I wanted without the php. Now I'm trying to combine the two and they're not going together. For instance when I add

 

<?php require_once ("scripts/dbConnection.php") ?>

 

nothing happens. Likewise with anyother include/require statements, just blank spots on the page like it's not being read at all. What gives?

Link to comment
Share on other sites

For that particular statement, you need a semi-colon

 

<?php require_once ("scripts/dbConnection.php"); ?>

 

It's coder's choice when mixing PHP and HTML to do inline PHP calls, but it sure causes problems up front, and then more problems when you need to trouble-shoot. I always recommend you avoid inline coding whenever possible.

 

PhREEEk

Link to comment
Share on other sites

Well then how do I alter this:

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1-strict.dtd">
    
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

    <head>
        <title>****</title>
        <link rel="stylesheet" href="css/global.css">
        <?php require_once("scripts/dbconnection.php"); ?>
    </head>

 

To make it work? 'cause now I have problems with line 1

Link to comment
Share on other sites

PHP might be getting confused over the XML tag, try

<?php
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1-strict.dtd">
    
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

    <head>
        <title>****</title>
        <link rel="stylesheet" href="css/global.css">
        <?php require_once("scripts/dbconnection.php"); ?>
    </head>

 

Ken

Link to comment
Share on other sites

Alright thanks! That totally fixed that. Saving the file as .php and marking the xml as an echo statement worked. One more simple question. As I said it was months ago when I was working with this php, how do I define file paths? ie: the php scripts I'm trying to require_once are in the same main directory as the main directory as the main php file itself, in another folder. The page I'm trying to load is /var/www/scratch/testdisplay.php the script is in /var/www/scratch/scripts/dbConnection.php. The path I'm using for the require is scripts/dbconnection.php and I'm getting an error. What am I doing wrong?

 

PS. The error is

\Warning: require_once(scripts/dbconnection.php) [function.require-once]: failed to open stream: No such file or directory in /var/www/scratch/testdisplay.php on line 12

 

Fatal error: require_once() [function.require]: Failed opening required 'scripts/dbconnection.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/scratch/testdisplay.php on line 12

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.