Posted by:
brendan
(---.b-ras1.blp.dublin.eircom.net)
Hi,
Wonder if someone could help with the problem below. Got a web page that includes a header, footer and a link to a database. I can get the two Includes to work but can't seem to display the database fields in the main body of the page. What has me baffled is that it appears to be connecting to the database, (Opening the connection to the database server The connection worked. The link is: Resource id #3) but no text (see below for database text) is appearing on the screen. Yet I'm not getting a "page_not_found" message. I can go to the database in MYSQL console and query it successfully. Any help greatly appreciated.
Brendan
--------------------CODE FOR MAIN PAGE START-------------------
<?php
$page_name = $_REQUEST['name'];
/*[
localhost]
// Get the body of the page
mysql_connect("localhost","root",""
or die(mysql_error());
mysql_select_db("test"
or die(mysql_error());
$sql = "SELECT * from pages WHERE name='$page_name'";
print "Opening the connection to the database server<br>";
$link = mysql_connect("localhost","root", ""
;
print "The connection worked. The link is: $link <br>";
/*
--------------What is being selected from the database--------------
+----------+------------------------------------------------------------------------+
| name | body
|
+----------+------------------------------------------------------------------------+
| about_us | <h1>About Us</h1> ACME Toys has been established in 1850 to provide toys
| to children all over the world
+----------+------------------------------------------------------------------------+
1 row in set (0.00 sec)
----------------------------------------------------------------------
*/
$result = mysql_query($sql) or die(mysql_error() );
// If the page is not found, redirect to a static page
if(mysql_num_rows($result) == 0 ) {
header("Location: page_not_found.html"
;
}
$row = mysql_fetch_assoc( $result );
$body = stripslashes( $row["body"] );
// Include the header
include("c:/wamp/www/exemples/header.php"
;
// Print the body of the page
echo $body;
// Include the footer
include("c:/wamp/www/exemples/footer.php"
;
?>
--------------------CODE FOR MAIN PAGE END-------------------