eval(); *RESOLVED*

  • 15 years ago

    I'm having one of those annoying problems where everything works fine for ages, and then all of a sudden, out of the blue, without (consiously) changing anything, the same bit of code suddenly starks puking at you.


    The error I'm getting is:
    Parse error:  syntax error, unexpected T_STRING in d:\wwwroot\PHP\fisp\actions.php(216) : eval()'d code on line 3


    Line 216 is the last one of this snippet:

    Code:
    $emailtext = mysqli_query($database, "SELECT content FROM cms WHERE page = 'pwdreset'");


    $content = mysqlifetchobject($emailtext);


    $messagebody = $content->content;


    eval("\$messagebody = \"$messagebody\";");

    Now basically what that's doing, is getting the body of a pre-written email from the Content Management System in the database. Contained in the email are such things as $username and $password etc., so the eval line is necessary to make sure they're processed properly. I remember coding this part of the project ages ago and it took forever to get it right, and now it's suddenly cacked up!


    It retrieves the data from the database without any problems at all, and it doesn't abandon the script, ie. the error's not fatal, but it does screw with the $messagebody variable so I get a lovely blank email sent. And of course an ugly error at the top of the page.


    The following snippet from the PHP web site, which as far as I can see is doing exactly the same thing, works fine on my machine!

    Code:
    <?php
    $string = 'cup';
    $name = 'coffee';
    $str = 'This is a $string with my $name in it.';
    echo $str. "\n";
    eval("\$str = \"$str\";");
    echo $str. "\n";
    ?>


    Any help?


    RESOLVED by adding slashes with "addslashes();" before running the eval() function, then stripping them with "stripslashes();" afterwards

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“An idiot with a computer is a faster, better idiot” - Rich Julius