View Full Version : Pull PHP code from a database

10-14-2005, 01:44 AM
I'm currently building a site where all the diferent pages data comes from a MySql database. My basic page looks like this.


$hostname_database = "localhost";
$database_database = "database";
$username_database = "username";
$password_database = "pass";
$database = mysql_pconnect($hostname_database, $username_database, $password_database) or trigger_error(mysql_error(),E_USER_ERROR);
$id = (isset($_GET['id'])) ? $_GET[id] : 'home';
mysql_select_db($database_database, $database);
$query_data = "SELECT * FROM site where id = '$id'";
$data = mysql_query($query_data, $database) or die(mysql_error());
$row_data = mysql_fetch_assoc($data);
$totalRows_data = mysql_num_rows($data);

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<base target="_top" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo $row_data['title']; ?></title>

<link rel="shortcut icon" href="/favicon.ico" />
<?php echo $row_data['head']; ?>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<td colspan="3" id="header"><img src="images/logo.gif" alt="Brady Online" width="468" height="60" /></td>
<td rowspan="2" id="navside">
<?php include("include/menu.txt") ?>
<a href="http://www.freedomain.co.nr/" target="_blank"></a></td>
<td id="navtop"><?php include("include/funny.txt") ?></td>
<td rowspan="2" align="center" valign="top" id="spacer"></td>
<td id="content"><p><?php echo $row_data['data']; ?></p>

For a regular page it works great. The problem is when I try and use it to access PHP code. The PHP source is showing up on the page instead of being parsed by the server. Is there something a I can Change in my above script to make it parse the PHP code.

10-14-2005, 07:46 PM
I believe eval() (http://uk.php.net/eval) is what you want.