papaface Posted February 17, 2007 Share Posted February 17, 2007 Hello, I was wondering if someone can help me. Currently I have a html table in a database. The html table has php in it which allows me to generate keys and things when I select it from the database. However when I include it in my script the php tags in the html table do not get processed, so I end up with plain php tags. This is my code In a database field: <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td>Please activate your membership </td> </tr> <tr> <td><a href="http://llalala.com/somepage.php?k=<?php $randomnumber; ?>u=<?php $username_gen; ?>">Click on this link to activate your membership </a></td> </tr> <tr> <td>or copy and paste this link to your browser: http://llalala.com/somepage.php?k=<?php $randomnumber; ?>&&u=<?php $username_gen; ?></td> </tr> </table> I work that into my code: $username_gen = base64_encode($username); $emailselect = mysql_query("select content_content from content where content_name='email_activation_content'"); $emailfrom = mysql_query("select content_content from content where content_name='email_activation_from'"); $emailsubject = mysql_query("select content_content from content where content_name='email_activation_subject'"); list($email_content) = mysql_fetch_array($emailselect); list($email_from) = mysql_fetch_array($emailfrom); list($email_subject) = mysql_fetch_array($emailsubject); $to = $email_address; $subject = $email_subject; $message = $email_content; $headers="MIME-Version:1.0\n"; $headers .="Content-type:text/html;charset=iso-8859-1\n"; $headers .="From: ".$email_from."\n"; if(mail($to, $subject, $message, $headers)) { echo "We have now registered you as a member, thank you for registering, your username is " . $username; echo '<br>We have dispatched an activation email to the address provided. You must click on the link in the email to activate your membership.'; } Why when the html table is selected from the database isnt it processing the php? and how can I get it to do it? When the email is sent the user simply gets a link like this: http://llalala.com/somepage.php?k=<?php+$randomnumber;+?>&&u=<?php $username_gen;+?> Sorry about my bad explanation lol. Quote Link to comment Share on other sites More sharing options...
papaface Posted February 17, 2007 Author Share Posted February 17, 2007 Anyone have any suggestions? I need to get php to somehow process the php tags inside the variable $email_content.... Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 17, 2007 Share Posted February 17, 2007 If you have PHP code stored in the database then PHP will treat the code as a string. In order for PHP to parse the PHP code coming from a database you will need to pass through the eval function. So you do this when you get the data from the database: $email_content = eval("$email_content"); Quote Link to comment Share on other sites More sharing options...
papaface Posted February 17, 2007 Author Share Posted February 17, 2007 Thanks. I get this error though: Parse error: parse error, unexpected '<' in somefile.php(16) : eval()'d code on line 1 I used this code as it is a scaled down version of my first post: <?php require("includes/connect.php"); require("includes/selectdb.php"); $username = "papaface"; $randomnumber = md5(mt_rand()); $username_gen = base64_encode($username); $contents = mysql_query("select `content_content` from `content` where `content_name`='email_activation_content'"); list($content) = mysql_fetch_array($contents); $email_content = eval("$content"); echo $email_content; ?> The data it is trying to eval is: <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td>Please activate your membership </td> </tr> <tr>somesite.com/somefile.php?k <td><a href="http://somesite.com/somefile.php?k=<?= $randomnumber ?>&&u=<?= $username_gen ?>">Click on this link to activate your membership </a></td> </tr> <tr> <td>or copy and paste this link to your browser: http://somesite.com/somefile.php?k=<?= $randomnumber ?>&&u=<?= $username_gen ?></td> </tr> </table> Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 17, 2007 Share Posted February 17, 2007 because that's html with php inside, I think you'll need to have the start of it be a closing php tag so it can go back into the html. Quote Link to comment Share on other sites More sharing options...
papaface Posted February 17, 2007 Author Share Posted February 17, 2007 Thanks, works perfectly now Quote Link to comment Share on other sites More sharing options...
papaface Posted February 17, 2007 Author Share Posted February 17, 2007 Actually I do have a problem. How do I stop the eval() function from echoing it out the the browser. Since I am sending an email I dont want that to happen, but I still want it to be processed for when it sends the email. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 17, 2007 Share Posted February 17, 2007 I got my eval syntax wrong in my post, it should be like this: eval("\$email_content = \"{$email_content}\";"); Quote Link to comment Share on other sites More sharing options...
papaface Posted February 17, 2007 Author Share Posted February 17, 2007 I have just tried that, it doesnt echo it out the browser but it doesnt process the variables. I get an email which is exactly the same as before with the <?php tags showing, plus the <? at the start of the tables code in the db. Quote Link to comment Share on other sites More sharing options...
papaface Posted February 17, 2007 Author Share Posted February 17, 2007 Calling php gurus help please Quote Link to comment Share on other sites More sharing options...
papaface Posted February 17, 2007 Author Share Posted February 17, 2007 php.net says that I can use: As with anything that outputs its result directly to the browser, you can use the output-control functions to capture the output of this function, and save it in a string (for example). But how would i work that into this? Quote Link to comment Share on other sites More sharing options...
papaface Posted February 17, 2007 Author Share Posted February 17, 2007 I have tried to work in the output buffers as so: list($email_content) = mysql_fetch_array($emailselect); ob_start(); eval("\$email_content = \"{$email_content}\";"); $email_content = ob_get_contents(); list($email_from) = mysql_fetch_array($emailfrom); list($email_subject) = mysql_fetch_array($emailsubject); $to = $email_address; $subject = $email_subject; $message = $email_content; but i get this error: Parse error: syntax error, unexpected T_LNUMBER in somepage.php(33) : eval()'d code on line 1 Any help will be appreciated. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 17, 2007 Share Posted February 17, 2007 It is easier if you remove the php code tags from the content in your database and wrap your php variables in curly braces instead ({$myvar}); Then when you use the eval code I supplied earlier it will parse the variables. Quote Link to comment Share on other sites More sharing options...
papaface Posted February 17, 2007 Author Share Posted February 17, 2007 Okay, is this correct? <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td>Please activate your membership </td> </tr> <tr> <td><a href="http://some.com/activate.php?k={$randomnumber} ?>&&u={$username_gen}">Click on this link to activate your membership </a></td> </tr> <tr> <td>or copy and paste this link to your browser: http://some.com/activate.php?k={$randomnumber}&&u={$username_gen}</td> </tr> </table> somepage.php: $emailselect = mysql_query("select content_content from content where content_name='email_activation_content'"); $emailfrom = mysql_query("select content_content from content where content_name='email_activation_from'"); $emailsubject = mysql_query("select content_content from content where content_name='email_activation_subject'"); list($email_content) = mysql_fetch_array($emailselect); eval("\$email_content = \"{$email_content}\";"); //$email_content = eval("\$email_content = \"{$email_content}\";"); list($email_from) = mysql_fetch_array($emailfrom); list($email_subject) = mysql_fetch_array($emailsubject); $to = $email_address; $subject = $email_subject; $message = $email_content; because if it is, I get an email like this: Please activate your membership Click on this link to activate your membership or copy and paste this link to your browser: http://some.com/activate.php?k={$randomnumber}&&u={$username_gen} Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 18, 2007 Share Posted February 18, 2007 Just tested your code and I got it to work by adding the following: $email_content = addslashes($email_content); before: eval("\$email_content = \"{$email_content}\";"); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.