3

I have mysql database with code in 1 of the fields

test test test <?php $_GET['location']; ?>  test test

I am accessing display file test.php?location=abc and displaying that record from database in the following way

 This is my <?php echo $row_display_content['location']; ?>

And the only result I have got is

This is my

have no idea how to make it works, so dynamic values may be displayed inside the text from database

5
  • 6
    Databases are for data. Don't store code in them. Commented Mar 1, 2012 at 19:18
  • correct, but I would like to display dynamic data in some of the content stored inside database Commented Mar 1, 2012 at 19:19
  • Do your dynamic content display programmatically. How do you want php interpreter to understand this This is my <?php echo test test test <?php $_GET['location']; ?> test test; ?>. That is exactly what you are doing Commented Mar 1, 2012 at 19:21
  • dynamic content it's a location passed via $_get Commented Mar 1, 2012 at 19:23
  • okay cool, so how do I do This is my <?php echo "test test test $_GET['location'] test test"; ?> Commented Mar 1, 2012 at 19:28

3 Answers 3

4

Use the eval function. Btw, this is a terrible approach to whatever problem you're trying to solve.

http://php.net/manual/en/function.eval.php

Edit:

$code = 'test test test <?php $_GET[\'location\']; ?>  test test';

eval('?>'. $code);
Sign up to request clarification or add additional context in comments.

6 Comments

tried this one already and doesnt work, once you use eval you have got error
Agreed to this completely. There is countless ways of avoiding using eval. And if you get errors, then there is errors in the eval code rather than anything else.
@user974435 Try... eval('?> your code <?php echo "blah"; ?>');
<?php echo eval('?> $row_display_content['location']; <?php echo "blah"; ?>'); ?>
Use the eval function. Btw, this is a terrible approach to whatever problem you're trying to solve. php.net/manual/en/function.eval.php Edit: $code = 'test test test <?php $_GET[\'location\']; ?> test test'; eval('?>'. $code); doesnt work ;( same result
|
2

Try

echo "This is my ". eval('?>' . $row_display_content[\'location\'] . '<?php ');

Comments

1

Take a look at eval and you shouldn't include the php tags in your database entry. Furthermore, you should ask yourself if you actually want to store this in your database.

2 Comments

doesn't work even once I removed <?php ?> tags form DB same error
this is how I used eval <?php echo eval($row_display_content['location']); ?>

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.