Jump to content

[SOLVED] 'include' function not working amidst script


xProteuSx

Recommended Posts

Here is the problem:

 

If I use this, the script works:

 

<?php some miscellaneous code; ?><?php include="whatever.php";?><?php some miscellaneous code; ?>

 

However, if I do this it does not:

 

<?php

some miscellaneous code;

include="whatever.php";

some miscellaneous code;

?>

 

What the haps??

Link to comment
Share on other sites

This is the version with the include function commented out.  It works perfectly.

 

{

echo '<center>';

echo '<table width=\"400\">';

echo '<tr>';

echo '<tr height=3>';

echo '<td></td>';

echo '<tr>';

echo '<tr border=1>';

echo '<td bgcolor=#d0d0d0 width=120><font size=+2><center><b>Members List</b></center></font></td>';

echo '<tr>';

echo '<tr height=8>';

echo '<td></td>';

echo '<tr>';

echo '</table>';

echo '</center>';

 

//include "include/db.php";

 

mysql_connect('server','user','pass') or die ('Unable to connect to MySQL Server');

mysql_select_db('database') or die ('Unable to select DB');

 

$query = 'SELECT users_handle FROM users';

$result = mysql_query($query) or die ('Error in query: ' . mysql_error());

 

etc.

 

}

 

 

This is the version with the include function called up.  It does not work.

 

{

echo '<center>';

echo '<table width=\"400\">';

echo '<tr>';

echo '<tr height=3>';

echo '<td></td>';

echo '<tr>';

echo '<tr border=1>';

echo '<td bgcolor=#d0d0d0 width=120><font size=+2><center><b>Members List</b></center></font></td>';

echo '<tr>';

echo '<tr height=8>';

echo '<td></td>';

echo '<tr>';

echo '</table>';

echo '</center>';

 

include "include/db.php";

 

$query = 'SELECT users_handle FROM users';

$result = mysql_query($query) or die ('Error in query: ' . mysql_error());

 

etc.

 

}

 

Contents of db.php:

 

------------------------------------------------------------------------------------------------------

$server = "server";// Your MySQL Server (usually "localhost")               

$db_user = "username";// Your MySQL Username                                       

$db_pass = "password";// Your MySQL Password                                       

$database = "database";// Database Name

 

mysql_connect('$server','$db_user','$db_pass') or die ('Unable to connect to MySQL Server');

mysql_select_db('$database') or die ('Unable to select DB');

------------------------------------------------------------------------------------------------------

 

That's all ...

 

 

Link to comment
Share on other sites

You have over 80 posts... please use BBCode code tags with a <?php at the top of each code snippet. That way we get color coded code that is easier to troubleshoot.

 

Please replace your db.php with this. run the script that includes db.php. Does "I died in db.php!" appear onscreen?

 

<?php
die("I died in db.php!");
$server = "server";// Your MySQL Server (usually "localhost")                 
$db_user = "username";// Your MySQL Username                                        
$db_pass = "password";// Your MySQL Password                                        
$database = "database";// Database Name

mysql_connect('$server','$db_user','$db_pass') or die ('Unable to connect to MySQL Server');
mysql_select_db('$database') or die ('Unable to select DB');
?>

 

PhREEEk

Link to comment
Share on other sites

The include file does not contain <?php and ?> tags, so the contents of it is not parsed.

 

BTW: The pseudo code examples in the first post are not the same as what the actual two code examples are doing. No one would have been able to help you based on the information in the first post. The only way to get specific with what your code is or is not doing is if you post your actual code.

Link to comment
Share on other sites

Got it figured out ... Just had to change this:

 

mysql_connect('$server','$db_user','$db_pass') or die ('Unable to connect to MySQL Server');

mysql_select_db('$database') or die ('Unable to select DB');

 

To this:

 

mysql_connect($server,$db_user,$db_pass) or die ('Unable to connect to MySQL Server');

mysql_select_db($database) or die ('Unable to select DB');

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.