include problem

This is a discussion on "include problem" within the PHP Forum section. This forum, and the thread "include problem are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Aug 1st, 2007, 10:50
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Unhappy include problem

Right,
I have a php script that shows how many users there are in the database:


PHP: Select all

<?php //how many users

$dbhost "localhost";
$dbname "web";
$dbuser "alex";
$dbpass "pass";

//Connect to database

mysql_connect $dbhost$dbuser$dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());


$userquery "select username from users";
$douserquery mysql_query($userquery) or die(mysql_error());
$userstotal mysql_num_rows($douserquery);
echo 
"Currently we have " .$userstotal" users";
?>
and I'm using this to link to it on the index.php page (root) :

PHP: Select all

<?php include('/content/totalusers.php'); ?>

But nothing turns up when i include it

i tried putting "12" before "<?php" and "34" after "?>" but it came up as "12 34".
What's wrong?
You can have more than 1 include on a page right?
Because it's also including 'navigation.php'
thanks
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Aug 1st, 2007, 10:52
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: include problem

oh forgot to say the script works,
as in just navigating to /content/totalusers.php
will show "Currently we have x users"
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Aug 1st, 2007, 11:39
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: include problem

You can include more than one page, that's not the problem. Make sure the url is right (try replacing 'include' with 'require' and see if you get errors).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Aug 1st, 2007, 12:06
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: include problem

You can use relative paths in include.

So your include should be something like this

PHP: Select all

<?php include('../content/totalusers.php'); ?>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Aug 1st, 2007, 12:57
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: include problem

umm it still didn't work :/
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Aug 1st, 2007, 13:58
Reputable Member
Join Date: Jul 2007
Location: UK, Essex
Age: 21
Posts: 172
Thanks: 0
Thanked 1 Time in 1 Post
Re: include problem

hey try

<!--#include file ="folderdestination/incfilename.inc" -->
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Aug 1st, 2007, 14:19
Reputable Member
Join Date: Apr 2007
Location: Scotland
Age: 17
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
Re: include problem

are you sure you have the path to the include right?

Where is the include found?
www.yourdomain.com/content/totalusers.php ? or something like www.yourdomain.com/php/content/totalusers.php ?

Maybe you should take the first slash off of the include path. Like this...

<?php include('content/totalusers.php'); ?>

Last edited by JacobHaug; Nov 13th, 2007 at 13:58. Reason: Taking out main domain
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Aug 1st, 2007, 14:42
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: include problem

taking the slash of worked
thanks
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Aug 1st, 2007, 15:36
Reputable Member
Join Date: Apr 2007
Location: Scotland
Age: 17
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
Re: include problem

lol. No problem.

using the slash makes the url: http://www.yourdomain.com/content/
but without it makes it: http://www.yourdomain.com/yourfolder/content/

Just so you know.

Last edited by JacobHaug; Nov 13th, 2007 at 13:59. Reason: Removed at users request!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Aug 8th, 2007, 08:19
Junior Member
Join Date: Aug 2007
Location: London
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Re: include problem

Quote:
Originally Posted by Blake121 View Post
using the slash makes the url: http://www.yourdomain.com/content/
but without it makes it: http://www.yourdomain.com/yourfolder/content/

Just so you know.
True for the browser, but remember that PHP is server side, and when you include files with include/require (or better practice, include_once/require_once), then you are (usually) specifying and including a file path and not a URI.

So include('/content/totalusers.php') was trying to include totalusers.php from the directory /content (i.e. directory content in the root directory) rather than from the directory 'content' in the same directory as the main script. PHP will emit a warning when it cannot include a file,
but if displaying errors has been disabled then no error would be seen, and in
this case logging would probably be to a file. It's a good idea to find out where
errors are going as diagnosing problems is tricky without that!

Coding the correct include path can sometimes be tricky in PHP as the current directory
is not always where you expect it to be or the same in all cases. This is particularly the case if
file A.php includes subdir/B.php, and A.php is included from files in different directories.
One technique is to construct an absolute path based on where a script is running. The pseudo constant
__FILE__ holds the currently executing files full path, and using the function dirname(), you
can extract the directory in order to locate files relative to that.

e.g. in A.php:

include_once dirname(__FILE__) . '/subdir/B.php';

This ensures that no matter where A.php is located and independent of the current
directory, if subdir/B.php is always in the same directory as A.php
then A.php can include B.php no matter where the files are located, what the current
directory is and where A.php has been included from.

hth

Last edited by JacobHaug; Nov 13th, 2007 at 14:00.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Aug 8th, 2007, 13:56
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: include problem

*stands and gapes in awe of this wonderfully elegant solution to one of his biggest problems*
Now that was interesting.

Thanks ioncube
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Aug 8th, 2007, 14:14
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: include problem

Wow big post
and handy
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
include

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I use #include within an If Then statement? Donny Bahama Classic ASP 5 Jul 30th, 2006 18:29
js include timmytots JavaScript Forum 5 Jul 8th, 2006 12:43
JS include timmytots JavaScript Forum 5 Jun 16th, 2006 01:49
Help need with php include!! allstar PHP Forum 7 Dec 29th, 2005 15:09
Include Virtual on IIS jakenoble PHP Forum 3 Mar 8th, 2004 07:22


All times are GMT. The time now is 00:22.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42