Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    New Coder
    Join Date
    Jan 2012
    Location
    Hastings, East Sussex, UK
    Posts
    34
    Thanks
    21
    Thanked 0 Times in 0 Posts

    Problem with include!

    I have written a couple of scripts to connect to my MYSQL database. I have used this method many times before, but it keeps coming up with this error message:
    Warning: include(feedback_connectphp) [function.include]: failed to open stream: No such file or directory in /homepages/43/d344817611/htdocs/Test/feedback.php on line 2

    Warning: include() [function.include]: Failed opening 'feedback_connectphp' for inclusion (include_path='.:/usr/lib/php5') in /homepages/43/d344817611/htdocs/Test/feedback.php on line 2

    Fatal error: Call to undefined function doDB2() in /homepages/43/d344817611/htdocs/Test/feedback.php on line 3

    I have check both scripts and can't find any errors (feedback_connect.php & feedback.php). The only annomoly that I can see is that in the error message is that the 'feedback_connect.php' does not have a dot(period).
    Here is the code:
    feedback_connect.php
    Code:
    <?php
    function doDB2() {
    	global $mysqli;
    
    	//connect to server and select database; you may need it
    	$mysqli = mysqli_connect(...);
    echo "CONNECTED";
    Break;
    	//if connection fails, stop script execution
    	if (mysqli_connect_errno()) {
    		printf("Connect failed: %s\n", mysqli_connect_error());
    		exit();
    	}
    }
    echo "CONNECTED";
    ?>
    feedback.php
    Code:
    <?php
    include(feedback_connect.php);
    doDB2();
    $fback_sql = "INSERT INTO feedback (title), (firstname), (lastname), (email), (comments)
    VALUES ('".$POST[title]."', '".$POST[firstname]."', '".$POST[lastname]."', '".$POST[email]."', '".$POST[comments]."')";
    $fback_res = mysqli_query($mysqli, $fback_sql) or die(mysqli_error($mysqli));
    $header = "From: webmaster@1066cards4u.co.uk" . "\r\n";
    $to = '".POST[email]."';
    $subject = "Feedback";
    $txt = "Thank you for your feedback.  \nWe will read your comments and email you again as to our actions";
    mail($to, $subject, $txt, $header);
    mail("webmaster@1066cards4u.co.uk", "Posting", "A feedback posting has been sent");
    mysqli_close(mysqli);
    mysqli_free_result($fback_res);
    ?>
    Can anyone see something that I am missing?
    Last edited by Fou-Lu; 12-16-2012 at 06:41 PM.

  • #2
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,304
    Thanks
    11
    Thanked 283 Times in 282 Posts
    I think you're just missing the quotes around the file name:
    PHP Code:
    include("feedback_connect.php"); 

  • Users who have thanked tracknut for this post:

    rockyhudson (12-17-2012)

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,345
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    Quote Originally Posted by rockyhudson View Post
    Warning: include(feedback_connectphp) [function.include]: failed to open stream: No such file or directory in /homepages/43/d344817611/htdocs/Test/feedback.php on line 2
    Quote Originally Posted by tracknut View Post
    I think you're just missing the quotes around the file name:
    PHP Code:
    include("feedback_connect.php"); 
    Normally PHP would raise an undefined constant error if that were the case trucknut and those should be single quotes unless you have a variable in there.

    It's interesting how that error message doesn't have a . for the php extension: feedback_connectphp instead of feedback_connect.php

    I can't help but wonder if there is something else going on here.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    rockyhudson (12-17-2012)

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I would have expected to see an undefined constant error for both FEEDBACK_CONNECT and PHP (with the dot of course being treated as concat) as well. PHP reverts from constant to string if it cannot find a defined constant with that name. I don't know why they designed it that way tbh I hate it.
    The quotes should be all you need (and either double or single would be fine; theoretically single would be faster as it guarantees no parsing with in it [I also prefer single for strings but I don't know where I got that habit from since pretty much every other language uses single quotes for chars only]).

  • Users who have thanked Fou-Lu for this post:

    rockyhudson (12-17-2012)

  • #5
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,304
    Thanks
    11
    Thanked 283 Times in 282 Posts
    I just did a quick test on this, and the error I get on a simple one-line script with an include missing the quotes is the same as the OP's errors. I agree, tango, it seems to be an odd error, but I do suspect that's the bug in the code.

    Dave

  • Users who have thanked tracknut for this post:

    rockyhudson (12-17-2012)

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I trigger notice on the constants and warning on the inclusion failure. You sure its not just your error reporting being too shallow?
    Code:
    D:\Server\PHP\php-5.4.0>php -r "print include(a.php);"
    PHP Notice:  Use of undefined constant a - assumed 'a' in Command line code on line 1
    
    Notice: Use of undefined constant a - assumed 'a' in Command line code on line 1
    
    PHP Notice:  Use of undefined constant php - assumed 'php' in Command line code on line 1
    
    Notice: Use of undefined constant php - assumed 'php' in Command line code on line 1
    PHP Warning:  include(aphp): failed to open stream: No such file or directory in  Command line code on line 1
    
    Warning: include(aphp): failed to open stream: No such file or directory in Command line code on line 1
    PHP Warning:  include(): Failed opening 'aphp' for inclusion (include_path='.;C:\php\pear') in Command line code on line 1
    
    Warning: include(): Failed opening 'aphp' for inclusion (include_path='.;C:\php\pear') in Command line code on line 1

  • Users who have thanked Fou-Lu for this post:

    rockyhudson (12-17-2012)

  • #7
    New Coder
    Join Date
    Jan 2012
    Location
    Hastings, East Sussex, UK
    Posts
    34
    Thanks
    21
    Thanked 0 Times in 0 Posts
    Hi All

    I have added the quotes and get exactly the same error?? Including the missing period in the filename.

    What settings do I need to change to get deeper reporting?

  • #8
    New Coder
    Join Date
    Apr 2010
    Posts
    55
    Thanks
    0
    Thanked 4 Times in 4 Posts
    error_reporting(E_ALL);

    as the first line of code should show you notices etc.
    Hosting Reviews and Discounts: Bluehost Coupon and Hostmonster Coupon

  • Users who have thanked alemcherry for this post:

    rockyhudson (12-17-2012)

  • #9
    New Coder
    Join Date
    Jan 2012
    Location
    Hastings, East Sussex, UK
    Posts
    34
    Thanks
    21
    Thanked 0 Times in 0 Posts
    Hi All

    Forgot to say that I am running this on my remote site run by my ISP, so I can't change any reporting settings.

    Does anyone have any other ideas as to why this is still erroring?

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by rockyhudson View Post
    Hi All

    Forgot to say that I am running this on my remote site run by my ISP, so I can't change any reporting settings.

    Does anyone have any other ideas as to why this is still erroring?
    Many ini changes can be performed inline with the script. Error reporting is one of them with a specific function just to change it.
    If you've modified it to add the quotes and it still shows the same error, you are running a cached page. Provide it with a random querystring and it should kick out a new script result.

  • Users who have thanked Fou-Lu for this post:

    rockyhudson (12-17-2012)

  • #11
    New Coder
    Join Date
    Jan 2012
    Location
    Hastings, East Sussex, UK
    Posts
    34
    Thanks
    21
    Thanked 0 Times in 0 Posts
    Hi All

    I have just tried it on localhost and it does not error, so must be a problem at my ISP I guess.

    However now having MYSQL problem, but will repost in the appropriate forum.

  • #12
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,345
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    Please post your latest code that you are using on your ISP. Do not give up, just because it doesn't work straight away doesn't mean we can't get to the bottom of it. It's only an include, it's not rocket science. We can and will (if you're prepared to give us chance) get to the bottom of this.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    rockyhudson (12-17-2012)

  • #13
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by rockyhudson View Post
    Hi All

    I have just tried it on localhost and it does not error, so must be a problem at my ISP I guess.

    However now having MYSQL problem, but will repost in the appropriate forum.
    Did you upload a modified copy to the server as well?
    Don't forget to force a random querystring through to hopefully get a refreshed result.

  • Users who have thanked Fou-Lu for this post:

    rockyhudson (12-17-2012)

  • #14
    New Coder
    Join Date
    Jan 2012
    Location
    Hastings, East Sussex, UK
    Posts
    34
    Thanks
    21
    Thanked 0 Times in 0 Posts
    Hi Tango

    The include error was actualy because I had left the double quotes off of the POSTed variables in the MYSQL INSERT statement. Alas, there is now something wrong in the syntax that I can't spot. As this is now a MYSQL problem I have posted a new thread on that forum.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •