Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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);
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.