woodsonoversoul Posted November 21, 2007 Share Posted November 21, 2007 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? Quote Link to comment Share on other sites More sharing options...
Dane Posted November 21, 2007 Share Posted November 21, 2007 are u adding.. ";" at the end? <?php require_once ("scripts/dbConnection.php"); ?> Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 21, 2007 Share Posted November 21, 2007 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 Quote Link to comment Share on other sites More sharing options...
woodsonoversoul Posted November 21, 2007 Author Share Posted November 21, 2007 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? Quote Link to comment Share on other sites More sharing options...
woodsonoversoul Posted November 21, 2007 Author Share Posted November 21, 2007 Even adding simple echo statements do not work Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 21, 2007 Share Posted November 21, 2007 an echo statement, if you want to echo out a simple variable can be <?=$variable ?> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 21, 2007 Share Posted November 21, 2007 Does your file have a ".php" extension? If it's ".html", php won't be invoked by the webserver. Ken Quote Link to comment Share on other sites More sharing options...
woodsonoversoul Posted November 21, 2007 Author Share Posted November 21, 2007 so to use php anywhere on the page I have to call the whole thing php? Even if I'm just, like, including a footer? Quote Link to comment Share on other sites More sharing options...
revraz Posted November 21, 2007 Share Posted November 21, 2007 Yes, PHP will not get parsed if the file is called something other than .php unless you add an entry in your .htaccess to include those files be parsed as PHP (which is more effort with the same result). Quote Link to comment Share on other sites More sharing options...
woodsonoversoul Posted November 21, 2007 Author Share Posted November 21, 2007 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 Quote Link to comment Share on other sites More sharing options...
Wes1890 Posted November 21, 2007 Share Posted November 21, 2007 ^ what kind of error is it outputting? Quote Link to comment Share on other sites More sharing options...
woodsonoversoul Posted November 21, 2007 Author Share Posted November 21, 2007 Parse error: syntax error, unexpected T_STRING in /var/www/scratch/testdisplay.php on line 1 Does anyone know of a good resource/example of how to enable php on html documents. I'd like to see how to do it both ways... Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 21, 2007 Share Posted November 21, 2007 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 Quote Link to comment Share on other sites More sharing options...
Wes1890 Posted November 21, 2007 Share Posted November 21, 2007 that's a good thought. because the <? makes the php file think that your starting your php code there, in which case, xml WOULD be and unexpected string Quote Link to comment Share on other sites More sharing options...
woodsonoversoul Posted November 21, 2007 Author Share Posted November 21, 2007 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 Quote Link to comment Share on other sites More sharing options...
woodsonoversoul Posted November 21, 2007 Author Share Posted November 21, 2007 never mind Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.