help with database data

Discussion in 'MySQL' started by nQQb, Nov 7, 2007.

  1. #1
    Hi, I'm learning MySQL databases and tables...I have a problem and need someone to please help me figure this out...

    Here's the situation:

    I have a webpage which is a template based site. I want to add text in table like this:

     <h1>{$sitename} Privacy Policy </h1>
      </div>
    
    </div>
    <div> 
      <div align="justify"><br />
        This privacy policy covers how we treat personal information that we collect and receive. We do not intend to collect any personal information from children under 13 unless we believe such collection to be permitted by law. Please see below for our policy with respect to children under 13. <br />
    PHP:
    when I enter this and create a table and call the page, I do not see {$sitename}...is there's a function I need to use so the page shows the site name when reading data from mysql table?

    Thanks for your help!
     
    nQQb, Nov 7, 2007 IP
  2. garbageman

    garbageman Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    the php code you retrieved will be treated as a string and will never be parsed. If you would like it to be parsed as php, try...
    
    // $string is the code that was returned from the mysql db
    eval("echo '".$string."'");
    
    PHP:
    WARNING: eval can be a serious security hole if you do not control what goes into your database. If this is for user-generated content, I would suggest using some type of template parser over this.
     
    garbageman, Nov 7, 2007 IP
  3. phper

    phper Active Member

    Messages:
    247
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #3
    nQQb, you need to assign the value of {$sitename} to your template engine. Check out the documentation for the templating system that you use.
    For Smarty, for example, it would be something like:
    $smarty = new Smarty();
    $smarty->assign("sitename", "My Site");
    $smarty->display("yourTplFile.tpl");
    PHP:
     
    phper, Nov 7, 2007 IP