Jump to content

Archived

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

purdles

Help with PHP include, please

Recommended Posts

Hi, new here. :D

And new to PHP but I have already installed a few scripts very successfully.

I am trying to get a Quote of the Day script to work properly, using the include function.  The script works fine on its own, I followed the instructions and if I type it in the browser, it displays.  Itdid not come with any directions on running it inside of an HTML page, which is what I need to do, so I just typed in <?php include("quotes.php"); ?>, but nothing shows up at all.  The php file is located in the same directory as the html file, from what i can see, it all looks set up right.  Like I said, it works fine if I direct browse to it.

Any ideas on how to fix this?  I appreciate all help!

Share this post


Link to post
Share on other sites
Can you post the code for "quotes.php" ? That would help. Is it possible that quotes.php doesn't output anything?

Share this post


Link to post
Share on other sites
This is quotes.php:


[code]
<style type="text/css">
<!--
.style1 {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
color: #E5E6E7;
}
.style2 {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-style: italic;
color: #E5E6E7;
}
-->
</style>
</head>
<body bgcolor="#696d71">
<img src="images/tip.gif" >&nbsp;&nbsp;<span class="style1">Quote of the day - <?php echo date("F jS, Y"); ?></span>
<table border="0" cellpadding="6" width="40%" cellspacing="0">
  <tr>
    <td width="100%" class="style2"><code>
    <?php


// *****************************************************************************
//  -------"The World's simplest PHP Message/Quote of the Day Script"----------
//
// Author: Mads S√łgaard (mads@acm.org)
// Homepage: http://www.emacs.dk/quote/
// Version: 1.0
//
//
// *****************************************************************************
// -------------------- Description --------------------------------------------
//
// "The World's simplest PHP Message/Quote of the Day Script" is a simple
// "quote-of-the-day script" that needs access to a MySQL database. It only
// consists of one script that's SIMPLE and hence easy to customize. This is how
// it works: You put any number of quotes/messages/whatever into the database,
// and then the script will show one quote every day. When all quotes have been
// shown, the script starts from the beginning of the quotes again. And if your
// quote-of-the-day page doesn't receive any visitors on a given day, the given
// quote-of-the-day will be shown the next day too. It simple, yet smart.
//
//
// *****************************************************************************
// -------------------- Installation --------------------------------------------
// 1. Upload the quote.php to your web server.
// 2. Change the following variables $DB_SERVER,$DB_USER, $DB_PASS, $DB_NAME
// (see below)
// 3. Create the needed tables in your database with the quotes.sql file.
// You can do it from the prompt (mysql -u[username] [-p] [database] < quotes.sql)
// or you can use the wonderful phpMyAdmin at http://www.phpwizard.net/projects/phpMyAdmin/
// 4. Point your browser to http://yourdomain/quotes.php
// 5. Add your own quotes to the database and custumize the script as you see fit.
//
// *****************************************************************************
// -------------------- Do you find this script useful? ------------------------
//
// Then by all means recommend it to other people! Or link back to me from your
// homepage (that would be greatly appreciated)
// You can also review my script and give it good grades at:
// http://www.hotscripts.com/PHP/Scripts_and_Programs/Quote_Display/
// (or anywhere else you may have found it)
//
// ******************************************************************************



// ****************************************
// Fill in your database information below
// ****************************************
$DB_SERVER = "mysql";
$DB_USER = "name";
$DB_PASS = "pwd";
$DB_NAME = "quotes";
// ****************************************

// ****************************************
// you do NOT have to edit below this line
// ****************************************
$con = mysql_connect($DB_SERVER, $DB_USER, $DB_PASS);
mysql_select_db($DB_NAME);

$getNoOfQuotesQuery = mysql_query("select count(*) from quotes", $con);
$no_of_quotes = mysql_result($getNoOfQuotesQuery,0);

$getMetaDataQuery = mysql_query("SELECT * FROM quotes_meta", $con);
$row = mysql_fetch_row($getMetaDataQuery);
$number_reached = $row[1];
$date_modified= $row[2];

// get the current day of the month (from 1 to 31)
$day_today = date("j");


if ($date_modified != $day_today){
// we have reached the end of the quotes
if ($number_reached >($no_of_quotes - 1)){
$number_reached = 1;
$query3 = mysql_query('UPDATE quotes_meta SET date_modified = "'.$day_today.'", number_reached = "'.$number_reached.'"', $con);
mysql_query($query3,$con);
} else {
// we haven't reached the end of the quotes
// therefore we increment $number_reached
$number_reached = $number_reached + 1;
$query3 = mysql_query('UPDATE quotes_meta SET date_modified = "'.$day_today.'", number_reached = "'.$number_reached.'"', $con);
mysql_query($query3,$con);
}
}

// we get the quote with 'id = $number_reached' from the database
$getQuoteQuery = mysql_query("SELECT quote,author FROM quotes WHERE id = ".$number_reached, $con);
$row = mysql_fetch_row($getQuoteQuery);

// we print the quote ($row[0]) and the author ($row[0])
echo $row[0]."<p align='right'><i>~ " . $row[1];

// close the database connection
mysql_close($con);
?>
</i></code></td>
  </tr>
</table>
<p>&nbsp;</p>
</body>
</html>
[/code]


*************************
Then there's an SQL file that goes with it....

Share this post


Link to post
Share on other sites
Have you done:
[code]
3. Create the needed tables in your database with the quotes.sql file.
You can do it from the prompt (mysql -u[username] [-p] [database] < quotes.sql)
or you can use the wonderful phpMyAdmin at http://www.phpwizard.net/projects/phpMyAdmin/
[/code]
? If so, do you get anything when you access quotes.php directly?

Share this post


Link to post
Share on other sites
Oh, and please use the [ code ]code here[ /code ] Tags (you will need to take the space's out for the tag to work). It makes things a lot easier to read.

Share this post


Link to post
Share on other sites
Sorry!  I fixed that above.

Yes, if I type it in directly, the quote script runs just fine.

Share this post


Link to post
Share on other sites
You're HTML file needs an extension of php instead of html for this to work.

Ken

Share this post


Link to post
Share on other sites
Here is something i found out on my server.
I have a similar issue that might be the same as yours.
I have a main.html page with a php script inside the file using the include statement. The html file doesnt display anything from the php, but if i copy the entire html file and name the file ending in php it works great.

Here is the contents of the main.html file:
<html>

<head>
<meta name="generator" content="Microsoft FrontPage 4.0">
<meta http-equiv="content-Type" content="text/html; charset=utf-8">

<style>
p
{
margin-top: 0px;
margin-bottom: 1px
}

body
{
font-family: "Times New Roman", serif;
font-size: 12pt;
font-weight: normal;
font-style: normal
}
</style>

</head>

<body>
<p style="text-align: center"><span style="font-family: Impact, sans-serif; color: #c10026"><font size="7">This is the Future Home Page of our web site.</font></span></p>
<br>
<p style="text-align: center"><span style="font-family: 'Century Gothic', sans-serif; color: #008080"><font size="6">This site is currently under construction.</font></span></p>
<p style="text-align: center"><span style="color: #008080"><span style="font-size: 16pt"><span style="font-family: 'Century Gothic', sans-serif">Please use the back button of your browser to exit this site.</span></span></span></p>
<br>
<p style="text-align: center"><span style="color: #800080; font-family: 'Arial Narrow', sans-serif"><font size="5">Thank you for your patience and hope to see you soon.</font></span></p>
<br>
<font face="helvetica,verdana,arial" size="-2"><p align="center">
<img src="Construction.gif">
</font>
<p align="center">&nbsp;</p>
<p align="center">
<font face="helvetica,verdana,arial" size="-2">This site is being hosted by <a href="http://www.ourwebsite.com" target="_blank">ourwebsite</a>, a Division of ourcompany,
Inc.</font></p>
</body>
</html>
<?PHP include ("counter.php"); ?>

If this same file is called main.php teh script runs, but not if it ends in .html

hope this helps some.
If at first you dont succeed your a programmer.

Share this post


Link to post
Share on other sites
You say that if you access the file directly that it works, but not when you include it in another page. I'm thinking the problem might be that you are trying to include a complete HTML page (i.e. head and body tags) within another HTML page. If the page that is calling the quote of the day page already has the HTML constructs, then edit the quote of the page day just to display the quote itself. In other words, remove the HTML, HEAD, and BODY tags.

Share this post


Link to post
Share on other sites
That was definitely it, it needed to be a PHP page also, the HTML was throwing it off.  So you can't include PHP in an HTML page?  I'm so happy because I sat here all day typing and configuring quotes (removing all those little ' and - ::) ) and if the script didn't work I was going to cry. Literally.  ;D

Thanks SOOOOO much everybody!  I appreciate all of your input!

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.