SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Dec 2002
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    processing php/html stored in a db

    I am having an issues with php processing variables that contain code.
    I have stored my html code with php vars in a table in a db and the use the following code to wrap up my returned result set into a variable which should be spitting out the php/html code.

    PHP Code:
      // Build the letter query to select the letter based off the variables above 
    $letterResults mysql_query("SELECT * FROM lgmb_letters WHERE letter_id='$letter_id'"); 
    if( !
    $letterResults )

      die(
    'Letter database error!'); 

    else 

      while (
    $msg mysql_fetch_array($letterResults)) { 
        
    // Lets do something with the results from the database 
        
    $msg_title   $msg['title']; 
        
    $msg_subject $msg['subject']; 
        
    $msg_message $msg['message'];

      } 

     
     echo (
    $msg_message); 
    What is happening is that the html is processed but not the php vars. When get rid of the query and simply type in my message which contains html and php vars it works perfectly.

    However this needs to be dynamic, so I am still trying to figure out how to get php to process the vars returned from my database.

  2. #2
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In what format were the php vars entered - using single quotes or double quotes. Any chance you can show us one!

  3. #3
    SitePoint Enthusiast 2slick's Avatar
    Join Date
    Jun 2004
    Location
    Philippines
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    does this variable $msg_message contains php/html codes ? Try the eval() function.

  4. #4
    SitePoint Wizard Dangermouse's Avatar
    Join Date
    Oct 2003
    Posts
    1,024
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Rasmus Lerdorf, BDFL of PHP
    If eval() is the answer, you're almost certainly asking the wrong question.

  5. #5
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    eval() is a great little function for when you're making small changes to somebody else's poorly written script, it can save a lot of time rewriting large portions

    However if you're starting from scratch, make sure you have a sound design plan to make sure you have a sound application.

  6. #6
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vB uses eval() for their templates, so I also started using it. But what is so wrong with that and how would it be done better?

  7. #7
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Most template engines use eval() as far as I'm aware. I probably came across wrong in my post, it has it's uses however I think that if you can design an application without using it then that's probably a better way.

    Templates are a different story, they come from you. Evaluating anything that could possibly contain user input is a very bad idea unless you are very careful with the data.

  8. #8
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The thread starter never mentioned user input, he basically retrieves a template from the database. But my question was also in regards to Ramus Lerdorf's comment.

  9. #9
    SitePoint Member
    Join Date
    Dec 2002
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe it would make more sense to show you what the output is :fill out the form here : form then select the first letter.

    Everything seems to be working except where the variables are just being displayed not processed by php.
    Last edited by paper_cut; Oct 8, 2004 at 12:32.

  10. #10
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For a lack of better suggestions: www.php.net/eval .


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
  •