Jump to content

PHP and Include()


aarushi2001

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/6105-php-and-include/
Share on other sites

[!--quoteo(post=359693:date=Mar 29 2006, 11:23 AM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Mar 29 2006, 11:23 AM) [snapback]359693[/snapback][/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
Link to comment
https://forums.phpfreaks.com/topic/6105-php-and-include/#findComment-21993
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.