Skipjackrick Posted February 4, 2009 Share Posted February 4, 2009 So as usual, I am including my Database connection file at the beginning of my db queries.....and its just displaying the code on the webpage???? Do any of you have an explanation for this? Take a look???? http://www.extremecoast.com/KW09/anglerstandings.php Just a short snippet of the code. </HEAD> <BODY BGCOLOR="#2f2f2f" TEXT="#ffffff" LINK="#0080ff" VLINK="#0080c0"> <?php include '/home/extremf3/public_html/layout/v2/kwheader.php'; ?> <img src="http://extremecoast.com/layout/v2/anglerstandings.jpg" border="0" align="middle"> <?php include '/home/extremf3/public_html/layout/v2/menu09.php'; ?> <TABLE width="765" border="0" cellpadding="8" align="middle" bgcolor="#343434"> <TR> <TD> <div id="content-wrap"> <div id="main"> <?php include '/home/extremf3/dbconnect.inc'; function get_angler_handle() { global $angler; global $anglerhandle; $query_d = "SELECT handle FROM anglers WHERE angler='$angler'"; $results_d = mysql_query($query_d) or die(mysql_error()); $row_d = mysql_fetch_array($results_d); extract ($row_d); $anglerhandle = $handle; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/143782-php-include-acting-weird/ Share on other sites More sharing options...
timmah1 Posted February 4, 2009 Share Posted February 4, 2009 shouldn't this include '/home/extremf3/dbconnect.inc'; be include '/home/extremf3/dbconnect.inc.php'; ? Quote Link to comment https://forums.phpfreaks.com/topic/143782-php-include-acting-weird/#findComment-754358 Share on other sites More sharing options...
Skipjackrick Posted February 4, 2009 Author Share Posted February 4, 2009 Nope, I've used this format before and it has worked for me in the past. However, I did try your suggestion and it gave me the same result. http://www.extremecoast.com/KW09/anglerstandings2.php shouldn't this include '/home/extremf3/dbconnect.inc'; be include '/home/extremf3/dbconnect.inc.php'; ? Quote Link to comment https://forums.phpfreaks.com/topic/143782-php-include-acting-weird/#findComment-754366 Share on other sites More sharing options...
menwn Posted February 4, 2009 Share Posted February 4, 2009 Have you insterted <?php ?> in your dbconnect.inc file? If yes please copy paste the code in your dbconnect.inc file because it is quite messy when displayed in the web site. Quote Link to comment https://forums.phpfreaks.com/topic/143782-php-include-acting-weird/#findComment-754369 Share on other sites More sharing options...
Snart Posted February 4, 2009 Share Posted February 4, 2009 Are you hosting your own site? If not, your provider may have disabled .inc as being recognized as PHP files. Quote Link to comment https://forums.phpfreaks.com/topic/143782-php-include-acting-weird/#findComment-754377 Share on other sites More sharing options...
Skipjackrick Posted February 4, 2009 Author Share Posted February 4, 2009 Have you insterted <?php ?> in your dbconnect.inc file? If yes please copy paste the code in your dbconnect.inc file because it is quite messy when displayed in the web site. Well, when I added the <?php ?> to the file its not displayed on the webpage. However, it still won't connect to MySQL. I changed the " .inc " extension to ".php" just to elminate any further questioning. My dbconnect file <?php // Database Variables $dbhost = "localhost"; $dbuser = "aaaaaa"; $dbpass = "aaaaaaaaaaaaa"; $dbname = "aaaaaaaa"; $MYSQL_ERRNO = ""; $MYSQL_ERROR = ""; // Connect To Database function db_connect() { global $dbhost, $dbuser, $dbpass, $dbname; global $MYSQL_ERRNO, $MYSQL_ERROR; $link_id = mysql_connect($dbhost, $dbuser, $dbpass); if(!$link_id) { $MYSQL_ERRNO = 0; $MYSQL_ERROR = "Connection failed to $dbhost."; return 0; } else if(!mysql_select_db($dbname)) { $MYSQL_ERRNO = mysql_errno(); $MYSQL_ERROR = mysql_error(); return 0; } else return $link_id; } // Handle Errors function sql_error() { global $MYSQL_ERRNO, $MYSQL_ERROR; if(empty($MYSQL_ERROR)) { $MYSQL_ERRNO = mysql_errno(); $MYSQL_ERROR = mysql_error(); } return "$MYSQL_ERRNO: $MYSQL_ERROR"; } // Print Error Message function error_message($msg) { printf("Error: %s", $msg); exit; } // Connection String Example # $link_id = db_connect($dbname); # if(!$link_id) error_message(sql_error()); # # $query = "SELECT * FROM test_table"; # $result = mysql_query($query); # # if(!$result) error_message(sql_error()); # # $data = mysql_fetch_array($result); ?> Quote Link to comment https://forums.phpfreaks.com/topic/143782-php-include-acting-weird/#findComment-754389 Share on other sites More sharing options...
Skipjackrick Posted February 4, 2009 Author Share Posted February 4, 2009 What is even weirder....Is that if I just paste the connection code directly into the page. It works just fine??? See http://www.extremecoast.com/KW09/anglerstandings2.php Quote Link to comment https://forums.phpfreaks.com/topic/143782-php-include-acting-weird/#findComment-754405 Share on other sites More sharing options...
Skipjackrick Posted February 4, 2009 Author Share Posted February 4, 2009 Well, I guess I will just bypass this and just manually type all of the db info into each page. I give up. Quote Link to comment https://forums.phpfreaks.com/topic/143782-php-include-acting-weird/#findComment-754410 Share on other sites More sharing options...
Solar Posted February 4, 2009 Share Posted February 4, 2009 <?php include ('/home/extremf3/dbconnect.inc'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/143782-php-include-acting-weird/#findComment-754460 Share on other sites More sharing options...
gevans Posted February 4, 2009 Share Posted February 4, 2009 can you show the whole contents of dbconnect.inc? Quote Link to comment https://forums.phpfreaks.com/topic/143782-php-include-acting-weird/#findComment-754468 Share on other sites More sharing options...
Philip Posted February 4, 2009 Share Posted February 4, 2009 @gevans: Have you insterted <?php ?> in your dbconnect.inc file? If yes please copy paste the code in your dbconnect.inc file because it is quite messy when displayed in the web site. Well, when I added the <?php ?> to the file its not displayed on the webpage. However, it still won't connect to MySQL. I changed the " .inc " extension to ".php" just to elminate any further questioning. My dbconnect file <?php // Database Variables $dbhost = "localhost"; $dbuser = "aaaaaa"; $dbpass = "aaaaaaaaaaaaa"; $dbname = "aaaaaaaa"; $MYSQL_ERRNO = ""; $MYSQL_ERROR = ""; // Connect To Database function db_connect() { global $dbhost, $dbuser, $dbpass, $dbname; global $MYSQL_ERRNO, $MYSQL_ERROR; $link_id = mysql_connect($dbhost, $dbuser, $dbpass); if(!$link_id) { $MYSQL_ERRNO = 0; $MYSQL_ERROR = "Connection failed to $dbhost."; return 0; } else if(!mysql_select_db($dbname)) { $MYSQL_ERRNO = mysql_errno(); $MYSQL_ERROR = mysql_error(); return 0; } else return $link_id; } // Handle Errors function sql_error() { global $MYSQL_ERRNO, $MYSQL_ERROR; if(empty($MYSQL_ERROR)) { $MYSQL_ERRNO = mysql_errno(); $MYSQL_ERROR = mysql_error(); } return "$MYSQL_ERRNO: $MYSQL_ERROR"; } // Print Error Message function error_message($msg) { printf("Error: %s", $msg); exit; } // Connection String Example # $link_id = db_connect($dbname); # if(!$link_id) error_message(sql_error()); # # $query = "SELECT * FROM test_table"; # $result = mysql_query($query); # # if(!$result) error_message(sql_error()); # # $data = mysql_fetch_array($result); ?> @OP: I'm looking at the page where you call the includes, where are you running your function 'db_connect()' ? Quote Link to comment https://forums.phpfreaks.com/topic/143782-php-include-acting-weird/#findComment-754550 Share on other sites More sharing options...
gevans Posted February 4, 2009 Share Posted February 4, 2009 @gevans: oh yea, my bad Quote Link to comment https://forums.phpfreaks.com/topic/143782-php-include-acting-weird/#findComment-754567 Share on other sites More sharing options...
Skipjackrick Posted February 4, 2009 Author Share Posted February 4, 2009 <?php include ('/home/extremf3/dbconnect.inc'); ?> Dang, stupid parentheses. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/143782-php-include-acting-weird/#findComment-754578 Share on other sites More sharing options...
Philip Posted February 4, 2009 Share Posted February 4, 2009 <?php include ('/home/extremf3/dbconnect.inc'); ?> Dang, stupid parentheses. Thanks! That shouldn't make a difference though, the parenthesis are optional. Because include() is a special language construct' date=' parentheses are not needed around its argument. Take care when comparing return value.[/quote'] Just a note: the reason it was showing the code, was because of 2 reasons: you didn't have <?php ?> tags, or your server isn't setup to execute .inc as php. Leaving it as .inc will run the risk of having your code shown again. Keep it at dbconnect.inc.php or dbconnect.php Quote Link to comment https://forums.phpfreaks.com/topic/143782-php-include-acting-weird/#findComment-754584 Share on other sites More sharing options...
Skipjackrick Posted February 4, 2009 Author Share Posted February 4, 2009 That shouldn't make a difference though, the parenthesis are optional. Because include() is a special language construct' date=' parentheses are not needed around its argument. Take care when comparing return value.[/quote'] I didn't think so either. Nevertheless, must have had an error then. Because I just copied and pasted that into my page and it worked like a champ. Quote Link to comment https://forums.phpfreaks.com/topic/143782-php-include-acting-weird/#findComment-754589 Share on other sites More sharing options...
Philip Posted February 4, 2009 Share Posted February 4, 2009 Just edited this in: Just a note: the reason it was showing the code, was because of 2 reasons: you didn't have <?php ?> tags, or your server isn't setup to execute .inc as php. Leaving it as .inc will run the risk of having your code shown again. Keep it at dbconnect.inc.php or dbconnect.php Quote Link to comment https://forums.phpfreaks.com/topic/143782-php-include-acting-weird/#findComment-754592 Share on other sites More sharing options...
Solar Posted February 4, 2009 Share Posted February 4, 2009 That shouldn't make a difference though, the parenthesis are optional. Because include() is a special language construct' date=' parentheses are not needed around its argument. Take care when comparing return value.[/quote'] I didn't think so either. Nevertheless, must have had an error then. Because I just copied and pasted that into my page and it worked like a champ. Haha, I didn't think it would matter either but I thought I'd post it. You are welcome Maybe you had; The single quotation mark instead of the double quotation mark. <?php include ('/home/extremf3/dbconnect.inc'); ?> Or.. <?php include "/home/extremf3/dbconnect.inc"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/143782-php-include-acting-weird/#findComment-754593 Share on other sites More sharing options...
Skipjackrick Posted February 4, 2009 Author Share Posted February 4, 2009 Just edited this in: Just a note: the reason it was showing the code, was because of 2 reasons: you didn't have <?php ?> tags, or your server isn't setup to execute .inc as php. Leaving it as .inc will run the risk of having your code shown again. Keep it at dbconnect.inc.php or dbconnect.php Cool Thanks for the info. I did change everything to .php extensions because that was mentioned earlier. Then I guess after I constructed the code correctly it worked. Multiple problems I guess. Thanks for the help guys. Quote Link to comment https://forums.phpfreaks.com/topic/143782-php-include-acting-weird/#findComment-754599 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.