Jump to content

PHP Include acting weird??


Skipjackrick

Recommended Posts

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;

}
?>

Link to comment
Share on other sites

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';

?

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

@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()' ?

 

Link to comment
Share on other sites

<?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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

 

 

Link to comment
Share on other sites

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";

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.