Can't see text from database field
Posted by: brendan (---.b-ras1.blp.dublin.eircom.net)
Date: August 17, 2010 09:25PM

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",""winking smiley or die(mysql_error());
mysql_select_db("test"winking smiley 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", ""winking smiley;
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"winking smiley;
}
$row = mysql_fetch_assoc( $result );
$body = stripslashes( $row["body"] );


// Include the header
include("c:/wamp/www/exemples/header.php"winking smiley;
// Print the body of the page
echo $body;
// Include the footer
include("c:/wamp/www/exemples/footer.php"winking smiley;

?>


--------------------CODE FOR MAIN PAGE END-------------------

Options: ReplyQuote
Re: Can't see text from database field
Posted by: toumimi (---.19.72-86.rev.gaoland.net)
Date: August 18, 2010 02:12AM

Since this forum is dedicated ti WampServer, thanks to ask your question on a coding forum.
You should also provide your sql request to them.

Good luck smiling smiley

Florian

WampServer Patch (Screenshots)
Topic EN : www.wampserver.com
Topic FR : www.wampserver.com

Options: ReplyQuote
Re: Can't see text from database field
Posted by: brendan (---.b-ras1.blp.dublin.eircom.net)
Date: August 18, 2010 07:05PM

Thanks for that Toumimi can you suggest any good coding forums?


Brendan

Options: ReplyQuote


Sorry, only registered users may post in this forum.