SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: eval()d code

  1. #1
    SitePoint Evangelist AlexC's Avatar
    Join Date
    Oct 2000
    Location
    Sheffield, UK
    Posts
    437
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    eval()d code

    Hi,

    i am trying to create a templating system for my site. In order to display variables (such as $siteaccesslevel) it appears i have to use eval

    i have been attempting to write a function to do this - heres what i got so far:

    in register.php
    PHP Code:
    if ($email==$cmail) {
        } else {
            
    doconnect();
            
    gettemplate($template "error_emailnomatch");
            exit();
        } 
    then in functions.php (which is included in a require statement at the top of the page)

    PHP Code:
    function gettemplate($template) {
        global 
    $template;
        
    $sql mysql_query("SELECT * FROM templates WHERE templatename='$template'");
        while ( 
    $row mysql_fetch_array($sql) ) {
            
    $code $row["code"];
            eval(
    "echo '$code';");
        }

    Finally, here is the code stored in the database - however it still only displays $email (or if i put <?php echo "$email"; ?> it says error in eval()d code

    Code:
    <html> <head> <title>AtomicForum :: Register</title> <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'> <style type='text/css'> <!-- input { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; font-weight: bold; color: #FFFFFF; background-color: #6666CC; border: #000000; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px} textarea { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; font-weight: bold; color: #FFFFFF; background-color: #6666CC; border: #000000; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px} --> </style> </head> <body bgcolor='#FFFFFF' text='#000000'> <table width='100%' border='0' cellspacing='0' cellpadding='0' height='100%'> <tr> <td> <table width='40%' border='5' cellspacing='0' cellpadding='0' align='center' bordercolor='#000000' bgcolor='#CCCCCC'> <tr> <td> <div align='center'><font face='Verdana, Arial, Helvetica, sans-serif' size='2'>Error: Emails do not match - click <a href='register.php'>here</a> to go back<br>The email you inputted was $email</font></div> </td> </tr> </table> </td> </tr> </table> <p>&nbsp;</p> </body> </html>
    Any help appreciated - i'm just getting to grips with php coding :-D

    Alex
    Nearly 7 years old!

  2. #2
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:
    PHP Code:
    $error gettemplate($template "error_emailnomatch");
    eval(
    "echo '$error';"); 
    Sean
    Last edited by seanf; Aug 1, 2001 at 11:45.
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually I think what you need to use if seanf's solution didn't work.

    PHP Code:
    $error gettemplate($template "error_emailnomatch");
    eval (
    "\$error = \"$error\";"); 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I meant to post this before!

    I use this when using files as templates:
    PHP Code:
    eval("echo stripslashes(\"$error\");"); 
    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  5. #5
    SitePoint Evangelist AlexC's Avatar
    Join Date
    Oct 2000
    Location
    Sheffield, UK
    Posts
    437
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm...i tried putting the code into register.php and it still wont work - with $email it says $email, and with <?php echo("$email"); ?> it wont work either
    Nearly 7 years old!


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
  •