|
-
Apr 3rd, 2006, 09:44 PM
#1
Thread Starter
Lively Member
[RESOLVED] PHP inside a MySQL text field... Can it be done?
Hello all.
Just wondering if there is a way of inserting PHP code in a database field, VARCHAR, MEDIUMTEXT, whatever, and have it echo as PHP code?
I have tried:
and
Code:
<? echo $GLOBALS['txt'][0]; ?>
But neither works.
Any help is appreciated.
Many thanks.
Last edited by solitario; Apr 5th, 2006 at 12:26 AM.
-
Apr 3rd, 2006, 11:48 PM
#2
Re: PHP inside a MySQL text field... Can it be done?
Use eval() or output it to a temporary file and include() that file.
Method 1:
PHP Code:
eval($GLOBALS['txt'][0]);
Method 2:
PHP Code:
file_put_contents('_temp.php', $GLOBALS['txt'][0]);
include('_temp.php']);
unlink('_temp.php');
Should you use the second method be sure that the PHP code has <?php ... ?> tags around it.
Last edited by penagate; Apr 3rd, 2006 at 11:51 PM.
-
Apr 4th, 2006, 01:15 AM
#3
Thread Starter
Lively Member
Re: PHP inside a MySQL text field... Can it be done?
Thanks penagate.
Perhaps I'm not doing this right.
Here is my query:
Code:
SELECT reservationist_name FROM reservationists WHERE reservationist_id=0;
Here is how I'm looping through the recordset:
Code:
while($row=mysql_fetch_object($sql)) {
$reservationist_name=$row->reservationist_name
}
Yet when I echo it to the page via "echo $reservationist_name;" it's giving me "eval($GLOBALS['txt'][0]);" as text. (The $txt array is right on the page, so I know it's there.) Anyone got an idea why it's not showing me the value of the variable? For the record it is:
Code:
$txt[0]='Reservationist Not Found';
I'd just hate to write that tiny string to a temporary file first, but I will if I have to.
Many thanks.
-
Apr 4th, 2006, 01:54 AM
#4
Re: PHP inside a MySQL text field... Can it be done?
I'm confused. Where is the PHP code stored in the databse?
eval(), will execute PHP code passed to it as a string - if you have actual PHP code in a database field then when you retrieve that field value you pass it to eval().
-
Apr 4th, 2006, 02:26 AM
#5
Conquistador
Re: PHP inside a MySQL text field... Can it be done?
Why can't you just echo $txt[0];
?
$reservationist_name = "echo $_GLOBALS['txt'][o];";
eval($reservantionist_name);
-
Apr 4th, 2006, 09:54 AM
#6
<?="Moderator"?>
Re: PHP inside a MySQL text field... Can it be done?
Using eval can lead to big security problems, make sure that a user cannot manipulate what is going to be executed. You wouldn't want code to be allowed to be executed which would allow the user to drop all the tables in your database.
-
Apr 5th, 2006, 12:25 AM
#7
Thread Starter
Lively Member
Re: PHP inside a MySQL text field... Can it be done?
 Originally Posted by penagate
...then when you retrieve that field value you pass it to eval().
Ah, that did it. Thanks!
 Originally Posted by da_silvy
Why can't you just echo $txt[0];
I would have, but I'm structuring my data so that 0 is a "catch all":
Code:
0 $GLOBALS['txt'][0]
1 Tom
2 Dick
3 Harry
The $txt array is going into an external language file.
And thanks, john tindell. I didn't know that.
Thanks folks. This one is resolved.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|