Hi,
I am relatively new to php however I am working on a site and appear to be
getting on quite well. Most of my pages are coded in php and work fine
however what I would like to do is be able to retrieve my content from a
mysql database. The set up is as follows:
Database contains several fields, but for this example I will only require
the Page Name and the Content fields. In page name I have the page name
i.e. whatson.php and I then have the entire contents of the page that I
worked on in my editor pasted in to the Content field.
I then create a basic php page that makes a connection to the database and
just searches for the page I want i.e. whatson.php and stores the result in
a variable called result.
I then echo out result but for some reason it just displays the php code and
does not appear to have interpreted it, can anyone help?. Sample code is
below:
<?php
// Create connection to database
$db = mysql_connect("localhost", "username","password") or die("Could not
connect : " . mysql_error());
mysql_select_db("myweb",$db);
$sql = "SELECT Content FROM pages WHERE PageName = 'whatson.php'" ;
$sql_result = mysql_query($sql,$db) or die("Couldn't execute query, please
notify webmaster.");
$result = mysql_query($sql);
//Main loop below which draws the screen
while ($row = mysql_fetch_array($sql_result)) {
echo $row[0]
}
?>
I am new to php so be nice :)
Thanks in advance
Rigga