Jump to content

Archived

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

aarushi2001

PHP and Include()

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.