php skript in html datei einbinden

B

BladeRunner

Guest
Hallo Leute,

ich brauch mal ein bisschen fachkundige Hilfe.
Ich möchte ein php skript "read.php" in eine html Datei "guestbook.html" einbinden.

Das skript selbst liest eine mysql Datenbank "cembook" aus und gibt es wieder. Soweit funktioniert es auch einwandfrei. Wenn ich diese Datei allerdings in eine html Seite einbinde - wird nix angezeigt. Ich habe die Einbindung mit include und require_once versucht - klappt nicht; jedenfalls wird wenn ich die html datei auf dem Server aufrufe nur diese angezeigt, d.h. ohne die Ergebnisse der Datenbankabfrgae.

Hier mal der Quellcode:

guestbook.html

CODE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>private Webseite von xxxxx</title><META NAME="Author" CONTENT="xxx">
<meta name="description" content="m"
<meta name="keywords" content="m">
<META NAME="keyphrases" CONTENT="m">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<link href="forAll.css" rel="stylesheet" type="text/css">
</head>

<body background="images/bg.gif" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="MM_preloadImages('images/about_on.gif','images/profil_on.gif','images/gast_on.gif','images/thru_the_eyes_on.gif','images/business_on.gif','images/contact_on.gif')">
<table width="760" height="100%" border="0" cellpadding="0" cellspacing="0" align="center" bgcolor="#D7D6D6">
<tr>
<td height="65" valign="top"><img src="images/top2.gif" width="760" height="65" border="0" usemap="#Map"></td>
</tr>
<tr>
<td height="45" valign="top" background="images/menu_bg.gif">
<a href="about.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('about','','images/about_me_on.gif',1)"><img src="images/about_me_off.gif" name="about" width="110" height="22" border="0"></a><a href="profil.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('profil','','images/profil_on.gif',1)"><img src="images/profil_off.gif" name="profil" width="100" height="22" border="0"></a><a href="guestbook.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('gast','','images/gast_on.gif',1)"><img src="images/gast_off.gif" name="gast" width="100" height="22" border="0"></a><a href="thru_my_eyes.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('thru_the_eyes','','images/thru_the_eyes_on.gif',1)"><img src="images/thru_the_eyes_off.gif" name="thru_the_eyes" width="100" height="22" border="0"><a href="business.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('business','','images/business_on.gif',1)"><img src="images/business_off.gif" name="business" width="100" height="22" border="0"></a></a><a href="contact.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('contact','','images/contact_on.gif',1)"><img src="images/contact_off.gif" name="contact" width="110" height="22" border="0"></a></td>
</tr>
<tr>
<td valign="top" bgcolor="#DFDFDF" class="forCopyright"><table width="100%" border="0" cellpadding="10" cellspacing="0">
<tr valign="top" bgcolor="#DFDFDF">
<td width="180" class="forTexts"><img src="images/left_guestbook1.gif" width="180" height="270"></td>
<td class="forTexts"> <p><img src="images/hdr_guestbook.gif" width="200" height="30"><br>
<br>
<? include("/read.php"); <'! Einbindung des read.php'>
?>
</p>
<p>Hier sollte das Gästebuch sichbar sein ???!!;.</p></td>
</tr>
</table></td>
</tr>
<tr>
<td height="30" align="center" valign="middle" background="images/down_blend.gif" class="forCopyright"><img src="images/down_blend.gif" width="9" height="30"></td>
</tr>
<tr>
<td height="30" align="center" valign="middle" background="images/down_bg.gif" class="forCopyright">All Rights Reserved 2004. [URL=http://www.xxxxxxxxxxx]http://www.xxxxxxxxxxx[/URL] | Design by <a href="http://www.xxxxxxxx" target="_blank"> c.candan</a></td>
</tr>
</table>
<map name="Map">
<area shape="rect" coords="11,24,227,61" href="index.html">
</map>
</body>
</html>


und hier das skript read.php

<?php require_once('connections/cembook.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];

$maxRows_rsRead = 3;
$pageNum_rsRead = 0;
if (isset($_GET['pageNum_rsRead'])) {
$pageNum_rsRead = $_GET['pageNum_rsRead'];
}
$startRow_rsRead = $pageNum_rsRead * $maxRows_rsRead;

mysql_select_db($database_guestbook, $guestbook);
$query_rsRead = "SELECT * FROM cembook ORDER BY cembook.marker DESC, cembook.`time`DESC";
$query_limit_rsRead = sprintf("%s LIMIT %d, %d", $query_rsRead, $startRow_rsRead, $maxRows_rsRead);
$rsRead = mysql_query($query_limit_rsRead, $guestbook) or die(mysql_error());
$row_rsRead = mysql_fetch_assoc($rsRead);

if (isset($_GET['totalRows_rsRead'])) {
$totalRows_rsRead = $_GET['totalRows_rsRead'];
} else {
$all_rsRead = mysql_query($query_rsRead);
$totalRows_rsRead = mysql_num_rows($all_rsRead);
}
$totalPages_rsRead = ceil($totalRows_rsRead/$maxRows_rsRead)-1;

$queryString_rsRead = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rsRead") == false &&
stristr($param, "totalRows_rsRead") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_rsRead = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_rsRead = sprintf("&totalRows_rsRead=%d%s", $totalRows_rsRead, $queryString_rsRead);

# © Peter Affentranger, ANP Affentranger Net Productions, www.anp.ch
function MakeHyperlink($text) {
$text = preg_replace("/((http(s?):\/\/)|(www\.))([\S\.]+)\b/i","<a href=\"http$3://$4$5\" target=\"_blank\">$2$4$5</a>", $text);
$text = preg_replace("/([\w\.]+)(@)([\S\.]+)\b/i","<a href=\"mailto:$0\">$0</a>",$text);
return nl2br($text);
}
?>
<?php include("header.php"); ?>
<table width="500" border="0" align="center" cellpadding="1" cellspacing="1">
<tr align="right">
<td colspan="2"><table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr class="forText">
<td width="50%"><a href="sign.php">Sign Guestbook</a></td>
<td width="50%" align="right">Total Messages: <?php echo $totalRows_rsRead ?></td>
</tr>
</table></td>
</tr>
<?php do { ?>
<tr valign="top">
<td width="120" class="forTableBgLeft">Date:</td>
<td width="380" class="forTableBgRight"><?php echo $row_rsRead['date']; ?></td>
</tr>
<tr valign="top">
<td width="120" class="forTableBgLeft">Name:</td>
<td width="380" class="forTableBgRight"><?php echo $row_rsRead['firstName']; ?> <?php echo $row_rsRead['lastName']; ?></td>
</tr>
<tr valign="top">
<td width="120" class="forTableBgLeft">Email:</td>
<td width="380" class="forTableBgRight"><?php echo MakeHyperlink($row_rsRead['email']); ?></td>
</tr>
<tr valign="top">
<td width="120" class="forTableBgLeft">Website:</td>
<td width="380" class="forTableBgRight"><?php echo MakeHyperlink($row_rsRead['website']); ?></td>
</tr>
<tr valign="top">
<td width="120" class="forTableBgLeft">Country:</td>
<td width="380" class="forTableBgRight"><?php echo $row_rsRead['country']; ?></td>
</tr>
<tr valign="top">
<td width="120" class="forTableBgLeft">Message:</td>
<td width="380" class="forTableBgRight"><?php echo $row_rsRead['comment']; ?></td>
</tr>
<tr valign="top">
<td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td background="images/dot.gif"><img src="images/dot.gif" width="3" height="5"></td>
</tr>
</table></td>
</tr>
<?php } while ($row_rsRead = mysql_fetch_assoc($rsRead)); ?>
</table>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="1">
<tr valign="middle" class="forTableBgLeft">
<td width="50%" height="20"><?php if ($pageNum_rsRead > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsRead=%d%s", $currentPage, max(0, $pageNum_rsRead - 1), $queryString_rsRead); ?>">Previous Page</a>
<?php } // Show if not first page ?></td>
<td width="50%" align="right"><?php if ($pageNum_rsRead < $totalPages_rsRead) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsRead=%d%s", $currentPage, min($totalPages_rsRead, $pageNum_rsRead + 1), $queryString_rsRead); ?>">Next Page</a>
<?php } // Show if not last page ?></td>
</tr>
</table>
<?php include("footer.php"); ?>
<?php
mysql_free_result($rsRead);
?>




HILFEEEEE !
 
Hallo

Schnellschuss vor dem Essen:

Suche
CODE <? include("/read.php"); <'! Einbindung des read.php'>
?>

ersetze mit

CODE <?php include("/read.php");
?>

Das read.php liegt ja im / , oder ??

Gruss
Roger
 
Hallo

Du kannst html in PHP dateien einfügen, nicht aber php in html...

warum?

weil HTML Seiten nicht durch den parser des Servers gjagt, sondern direkt angezeigt werden.


Warum muss die Seite denn guestbook.HTML heissen?
 
Beni hat Recht, und um das von ihm angesprochene Problem zu lösen musst du einfach folgende Zeile:
QUOTE AddType application/x-httpd-php .html
in die .htaccess schreiben und diese im root speichern. Sonst mach was Roger gesagt hat.

alain
 
benenne die guestbook.html doch einfach in guestbook.php um
 
Zurück
Oben