Results 1 to 2 of 2

Thread: Pull PHP code from a database

  1. #1
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Question Pull PHP code from a database

    I'm currently building a site where all the diferent pages data comes from a MySql database. My basic page looks like this.

    PHP Code:
    <?php

    $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); 
    ?>
    <?php
    $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">
    <head>
    <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']; ?>
    </head>
    <body>
      <tr><td> 
      <table width="100%" border="0" cellspacing="0" cellpadding="2">
      <tr>
        <td colspan="3" id="header"><img src="images/logo.gif" alt="Brady Online" width="468" height="60" /></td>
      </tr>
      <tr>
        <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>
      </tr>
      <tr>
        <td id="content"><p><?php echo $row_data['data']; ?></p>
          </td></tr>
        </table>
      </body>
    </html>
    <?php
    mysql_free_result
    ($data);
    ?>
    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.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I believe eval() is what you want.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •