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