Jump to content


Photo

Help with PHP include, please


  • Please log in to reply
9 replies to this topic

#1 purdles

purdles
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 20 October 2006 - 09:04 PM

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!

#2 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 20 October 2006 - 09:15 PM

Can you post the code for "quotes.php" ? That would help. Is it possible that quotes.php doesn't output anything?

#3 purdles

purdles
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 20 October 2006 - 09:20 PM

This is quotes.php:


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


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

#4 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 20 October 2006 - 09:36 PM

Have you done:
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/
? If so, do you get anything when you access quotes.php directly?

#5 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 20 October 2006 - 09:39 PM

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.

#6 purdles

purdles
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 20 October 2006 - 09:55 PM

Sorry!  I fixed that above.

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

#7 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 20 October 2006 - 09:57 PM

You're HTML file needs an extension of php instead of html for this to work.

Ken

#8 joebpa

joebpa
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 20 October 2006 - 10:00 PM

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.

#9 Psycho

Psycho
  • Moderators
  • Move along, nothing to see here
  • 11,892 posts
  • LocationCanada

Posted 20 October 2006 - 11:04 PM

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.
The quality of the responses received is directly proportional to the quality of the question asked.

I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net

#10 purdles

purdles
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 21 October 2006 - 12:31 AM

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users