LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-05-2008, 09:39 PM   #1
SoulShaker
LQ Newbie
 
Registered: Oct 2006
Posts: 12

Rep: Reputation: 0
PHP 'require' statement problem


I'm trying to teach myself PHP, and seem to be running into a problem. The error I am receiving is occuring on line 3. I added the 'or die' statement to give me a little bit more info. This is the error message I am receiving:

Warning: require(1) [function.require]: failed to open stream: No such file or directory in /var/www/index.php on line 3

Fatal error: require() [function.require]: Failed opening required '1' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/index.php on line 3


When using 'require', PHP seems to be treating it as a function rather than a statement, returning '1'.

Can anyone steer me in the right direction. Thanks.

Here is the code:

PHP Code:
<?php

require 'db_creds.php' or die(mysql_error());
require 
'db_connect.php';

?>

<?php

$query 
"SELECT SERVICE_TAG,NAME,BRAND,MODEL,DESCRIPTION FROM servers";
$result mysql_query($query);

$num mysql_numrows($result);

$i=0;
while (
$i $num) {

    
$serviceTag mysql_result($result,$i,"SERVICE_TAG");
    
$name mysql_result($result,$i,"NAME");

    
?> <h4>Server Tag: </h4> <?php echo $serviceTag
    
?> <h4>Name: </h4> <?php echo $name;

$i++;

}


?>

<?php
require 'db_close.php';
?>

Last edited by SoulShaker; 08-05-2008 at 09:42 PM.
 
Old 08-06-2008, 12:38 AM   #2
w3bd3vil
Senior Member
 
Registered: Jun 2006
Location: Hyderabad, India
Distribution: Fedora
Posts: 1,191

Rep: Reputation: 49
PHP fails to find your db_creds.php file.
You could add the following line if the db_creds.php is present in the /var/www directory.
Quote:
ini_set('include_path',ini_get('include_path').'/var/www');
You could also set up the main php configuration file, with
Quote:
include_path ="/var/www/";
 
Old 08-08-2008, 09:35 PM   #3
SoulShaker
LQ Newbie
 
Registered: Oct 2006
Posts: 12

Original Poster
Rep: Reputation: 0
Sorry about the delay. I tried these suggestions, and no cigar.

Does anyone else have any ideas.
 
Old 08-08-2008, 10:00 PM   #4
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
"no cigar" is diagnostically useless.

You have been told what the problem is; PHP is not finding your file db_creds.php. Why it is not finding it is up to you to figure out, or - in the alternative - provide US with enough information that we can sort it out.

Almost certainly, db_creds.php does not exist in the same directory as the script you are running, and it apparently does not exist in the path you have specified for search.

Since you have it as a require rather than an include, PHP fails when it isn't found. Just that simple.
 
Old 08-09-2008, 08:12 PM   #5
SoulShaker
LQ Newbie
 
Registered: Oct 2006
Posts: 12

Original Poster
Rep: Reputation: 0
Yes, the db_creds.php file is in /var/www. I have added the statement
PHP Code:
ini_set('include_path',ini_get('include_path').':/var/www'); 
to my code, so now the error is

Warning: require(1) [function.require]: failed to open stream: No such file or directory in /var/www/index.php on line 4

Fatal error: require() [function.require]: Failed opening required '1' (include_path='.:/usr/share/php:/usr/share/pear:/var/www') in /var/www/index.php on line 4

So I don't think the problem is that PHP is not finding the location of the file. Based on the error, it looks like it is somehow translating my file name into '1', which it then tries to open, but fails. Is there something that needs to be configured in PHP to change this? Oddly enough, I tried the code on a hostmonster.com web page, and it worked fine, so I'm guessing that there is something configured incorrectly in my PHP. I just did the default PHP5 install for Ubuntu 8.04.
 
Old 08-10-2008, 09:11 PM   #6
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
I have seen that problem before, and I have been trying to recall the details.

IIRC, I encountered this problem with a paypal installation while rehosting the site to a new server for a client. There was something wrong with how the session was being handled. More properly, there was something different between how the old server installation and the new server installation handled the session, and I had to modify a paypal module to issue a session_write_close() right at the beginning, followed immediately by a session_start().

I just checked my local copy of the old site and the new site, and yes, that is what I did.

Unfortunately, at this point I don't recall all the details of why I had to do it that way.

Might be a clue for you though.
 
Old 08-12-2008, 06:55 PM   #7
SoulShaker
LQ Newbie
 
Registered: Oct 2006
Posts: 12

Original Poster
Rep: Reputation: 0
Well, I'm humbled. The error ended up being a simple case of an un-escaped apostrophe. This error actually wasn't in the code that I posted above, but adding the 'or die (mysql_error())' gave me an error that made it seem like it was.

Anyway, I removed the 'or die' section, which then gave me the error that stated that the problem was actually in my db_connect.php file (something I may have noticed earlier had I read the original error a bit closer before throwing in the added error-checking).

Anyway, thank you guys for your help, and sorry for wasting anyone's time.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php if statement in an array secretlydead Programming 1 09-28-2007 05:08 AM
php source install require flex 2.5.4 ?? hottdogg Programming 2 06-29-2006 09:09 PM
php include()/require() script question atom Programming 11 08-19-2004 01:12 AM
NavBar and <?php require Gerardoj Programming 2 04-13-2004 02:04 PM
php - include, require and arrays gui10 Programming 1 02-05-2002 08:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration