I have this XML guestbook script and I'm having trouble getting the code from the mysql to a guestbook.php script. I tried post the XML code in the mysql, but it didn't work.
<?PHP
############################################################
# Written by Ryan Brill - [url]http://www.ryanbrill.com/[/url] #
# #
# This work is licensed under a Creative Commons Liscense #
# [url]http://creativecommons.org/licenses/by-sa/1.0/[/url] #
############################################################
###################### Set up the following variables ######################
#
#
$file = "guestbook.xml"; # name of the guesbook file
$writetop = true; /*
* set to true or false. If true, new entries will
* will be written to the top. If false, new entries
* will be written to the bottom.
*/
# #
##################### No need to edit below this line ######################
if (isset($_POST['submit'])) {
session_start();
# check for magic quotes
if (ini_get('magic_quotes_gpc') == true) {
$name = htmlspecialchars(trim(stripslashes($_POST['name'])));
$title = htmlspecialchars(trim(stripslashes($_POST['title'])));
$message = htmlspecialchars(trim(stripslashes($_POST['message'])));
}
else {
$name = htmlspecialchars(trim($_POST['name']));
$title = htmlspecialchars(trim($_POST['title']));
$message = htmlspecialchars(trim($_POST['message']));
}
# make sure required fields have been filled out
if (!empty($name) && !empty($message)) {
if (!isset($_SESSION['time']) || @$_SESSION['time']+30 < time()) {
$entry = " <entry>\n";
if (!empty($title)) {
$entry .= " <title>$title</title>\n";
}
$entry .= " <message>$message</message>\n"
." <name>$name</name>\n"
." <time>".time()."</time>\n"
." </entry>\n";
if ($writetop == true) {
$contents = file($file);
$lines = "";
for ($i=2; $i<count($contents); $i++) {
$lines .= $contents[$i];
}
$entry = "<?xml version=\"1.0\" ?>\n<guestbook>\n".$entry.$lines;
}
else {
$entry .= "</guestbook>";
}
$fp = fopen($file,'r+');
if ($writetop != true) {
fseek($fp, -12, SEEK_END); # find the position we want to write to
}
flock ($fp, LOCK_EX);
fwrite ($fp, $entry);
flock ($fp, LOCK_UN);
fclose ($fp);
$_SESSION['time'] = time();
}
else {
$errmsg = "You may only post once every 30 seconds";
}
}
else {
$errmsg = "Please fill out all required field";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>XML Guestbook</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="content-script-type" content="text/javascript" />
<meta http-equiv="content-style-type" content="text/css" />
<style type="text/css" media="all">@import "guestbook.css";</style>
</head>
<body>
<div id="guestbook">
<h1 style="margin: 0;"><img src="guestbook.png" width="170" height="37" alt="XML Guestbook" /></h1>
<div class="hr"></div>
<form action="<?PHP echo $_SERVER['PHP_SELF']; ?>" method="post">
<?PHP
if (isset($errmsg)) {
echo "<p id=\"error\">$errmsg</p>";
}
?>
<p><strong>Name *</strong><br />
<input type="text" name="name" <?PHP if (isset($errmsg)) { echo "value=\"$name\""; } ?> /><br />
<strong>Title</strong><br />
<input type="text" name="title" <?PHP if (isset($errmsg)) { echo "value=\"$title\""; } ?> /><br />
<strong>Message *</strong><br />
<textarea rows="7" cols="40" name="message"><?PHP if (isset($errmsg)) { echo $message; } ?></textarea><br />
<input type="submit" name="submit" value="post comment" /></p>
</form>
<p id="footermessage">* denotes a required field</p>
<?php
# function to handle the beginning tags
function tagBegin ($parser, $element, $attributes) {
$element = strtolower($element);
global $elem;
switch ($element) {
case 'entry':
$elem = "entry";
echo "\n <div class=\"entry\">";
break;
case 'title':
$elem = "title";
echo "<p class=\"title\">";
break;
case 'message':
$elem = "message";
echo "<p>";
break;
case 'name':
$elem = "name";
echo "<p class=\"footer\">Posted by ";
break;
case 'time':
$elem = "time";
echo " on ";
break;
default:
$elem = "default";
break;
}
}
# function to handle the data of each element
function cdataEater ($parser, $cdata) {
global $elem;
switch ($elem) {
case 'time':
if (is_numeric($cdata)) {
echo date("F d, Y h:i a", $cdata);
}
break;
default:
#split words that are more than 50 characters long
$message = explode(" ", $cdata);
$splitmessage = "";
foreach ($message as $word) {
$splitmessage .= wordwrap($word, 40, " ", 1)." ";
}
$message = $splitmessage;
echo $message;
//echo $cdata;
break;
}
}
# function to handle the ending tags
function tagEnd ($parser, $element) {
$element = strtolower($element);
switch($element) {
case 'entry':
echo " </div>\n";
break;
case 'title':
echo "</p>";
break;
case 'message':
echo "</p>";
break;
case 'name':
break;
case 'time':
echo "</p>\n";
break;
}
}
# create the parser and set the handling functions.
$parser = xml_parser_create();
xml_set_element_handler ($parser, 'tagBegin', 'tagEnd');
xml_set_character_data_handler ($parser, 'cdataEater');
# read the file.
$fp = @fopen ($file, 'r') or die ("Could not open guestbook file \"$file\" for reading");
while ($data = fread ($fp, filesize($file))) {
if (!xml_parse ($parser, $data, feof($fp))) {
echo 'XML parsing error: '
.@xml_error_string(@xml_get_error_code($xml_parser))
.' at line '.@xml_get_current_line_number($xml_parser).'.';
}
}
# free up the parser.
xml_parser_free($parser);
?>
</div>
<p class="footermsg">Proudly serving up valid <a href="http://validator.w3.org/check/referer">XHTML 1.1</a> and <a href="http://jigsaw.w3.org/css-validator/">CSS</a></p>
<p class="footermsg">
<!-- Creative Commons License -->
<a href="http://creativecommons.org/licenses/by-sa/1.0/"><img src="http://creativecommons.org/images/public/somerights.gif" alt="Creative Commons License" /></a><br />
This guestbook was created by <a href="http://www.ryanbrill.com/">Ryan Brill</a> and is licensed under a <a href="http://creativecommons.org/licenses/by-sa/1.0/" title="View the license">Creative Commons License</a>.
<!-- /Creative Commons License -->
<!--
<rdf:RDF xmlns="http://web.resource.org/cc/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<Work rdf:about="">
<license rdf:resource="http://creativecommons.org/licenses/by-sa/1.0/" />
</Work>
<License rdf:about="http://creativecommons.org/licenses/by-sa/1.0/">
<permits rdf:resource="http://web.resource.org/cc/Reproduction" />
<permits rdf:resource="http://web.resource.org/cc/Distribution" />
<requires rdf:resource="http://web.resource.org/cc/Notice" />
<requires rdf:resource="http://web.resource.org/cc/Attribution" />
<permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" />
<requires rdf:resource="http://web.resource.org/cc/ShareAlike" />
</License>
</rdf:RDF>
--></p>
</body>
</html>
I tried adding some codes but it wouldn't were such as :
$query = "SELECT html from users WHERE username='$my_quadrant'";
$show = mysql_query($query);
while ($row=mysql_fetch_array($show))
{
echo "$row[code=html]";
}
I treid switching $file = "guestbook.xml"; into $row[guestbook];