Jump to content


Photo

PHP and Include()


  • Please log in to reply
2 replies to this topic

#1 aarushi2001

aarushi2001
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 29 March 2006 - 04:20 PM

Hi,

I am using PHP 4.3.11. I have recently started coding in PHP and I need help.

I am trying to connect to the DB, I have created files: config.inc and opendb.inc, when I call these files using include() function, I get a blank page.

But if I dont use the include() and hard-code my php files, I am able to access the database.

Can anyone help me?

Thanks

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 29 March 2006 - 04:23 PM

Can you show us your code? Specifically how you use the includes? And is the code that you hardcode with the same code as in the files you include?

Info: PHP Manual


#3 aarushi2001

aarushi2001
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 29 March 2006 - 04:49 PM

[!--quoteo(post=359693:date=Mar 29 2006, 11:23 AM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Mar 29 2006, 11:23 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Can you show us your code? Specifically how you use the includes? And is the code that you hardcode with the same code as in the files you include?
[/quote]

Hi,

Thanks for such a quick response,

Code which include 'include()'

<?php
include 'config.php';
include 'opendb.php';

$query = "SELECT firstname FROM customers";
$result = mysql_query($query);

while ($line = mysql_fetch_array($result))
{
echo "$line[firstname] <br> $line[lastname]";

}

include 'closedb.php';
?>

Code which doesnot include 'include()'

<?php
$link = mysql_connect("mysql", "*****", "****");
mysql_select_db("***");

$query = "SELECT firstname, lastname FROM customers";
$result = mysql_query($query);

while ($line = mysql_fetch_array($result))
{
echo "$line[firstname] <br> $line[lastname]";

}

mysql_close($link);
?>

Thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users