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
https://forums.phpfreaks.com/topic/78264-html-working-with-php/
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
https://forums.phpfreaks.com/topic/78264-html-working-with-php/#findComment-396070
Share on other sites

Yeah I was using semicolons earlier, but then noticed some examples where they weren't used, so I took them out. Even with the semicolons, nothing happens.

 

It just makes the page so long if I have everything together and very confusing. Is it not a good idea to at least include headers and footers?

Link to comment
https://forums.phpfreaks.com/topic/78264-html-working-with-php/#findComment-396077
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
https://forums.phpfreaks.com/topic/78264-html-working-with-php/#findComment-396121
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
https://forums.phpfreaks.com/topic/78264-html-working-with-php/#findComment-396158
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
https://forums.phpfreaks.com/topic/78264-html-working-with-php/#findComment-396177
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.