PHP not executing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

PHP not executing

Post by Archy »

I have all the page's code for my website in a MySQL database, and then to get the code, I use this to get the code for the page, it works fine:

Code: Select all

<?php

include('admin/header.php'); // get connection information

$row = mysql_fetch_array($rs);
$msg = $row['public'];

include('admin/strings.php');

echo($msg);

?>
However, if I put any PHP code in the database, eg, <?php echo"hello"; ?> then it will not get executed, it just appears on the source like normal HTML (does not actually appear on page, you can just see it on the source if you go view->source). I have also tried it without the <?php and ?> but to no avail.

Does anybody know why this might be happening, and what I can do to actually get the code to execute correctly?

Thanks.
SBukoski
Forum Contributor
Posts: 128
Joined: Wed May 21, 2003 10:39 pm
Location: Worcester, MA

Post by SBukoski »

Check out the eval() function. I believe this does the trick for you.
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post by Archy »

OK, thanks, I realise that I have to use the eval() function now, but am slightly confused about how to add it in. I will try and list some of the ideas that I have, but I dont know which is right, and what the correct code would be.

Would I...
o Insert the code on the actual page where the code is inserted into the database, or
o Add the eval() function into the page that collects the information to be displayed

I am bot sure which of these is correct, but im sure one of them is :P

In any case, the code gets submitted to another page where it gets inserted into the database. The variable the code is in is called $update_code (nice and orriginal ;)). I was wondering what the code would be to actuall get it eval()'d to then put it in the database, cause I am also a bit confused about that "/

Thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it'd be eval'd coming out of the database.. you'll need to sanitize it going in and coming out, as someone may change it (bad boy!)
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post by Archy »

What do you mean when you say "you'll need to sanitize it going in and coming out"?

So what would the actual code for doing this, I looked on PHP.net and on the forums, but couldnt get anything to work :(
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

check it for the code which you allow. If anything else is encountered, strip it out, or kick out an error.
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post by Archy »

I have tried...

eval($msg);
$msg = eval($msg);

with quotes, without quotes, and many other ways, but none work =/
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what's $msg contain?
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post by Archy »

Code: Select all

<?php 

include('admin/header.php'); // get connection information 

$row = mysql_fetch_array($rs); 
$msg = $row['public']; 

include('admin/strings.php'); 

echo($msg); 

?>
:)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$rs is set inside header.php? or is set before the eval?
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post by Archy »

It is contained in admin/header.php, along with all the other connection information
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

wait a sec.. the code above is what is inside $msg, or where you are eval'ing $msg?
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post by Archy »

$msg is the code that is from the database that I am wanting to show.

I need to eval() the $msg variable to get the correct code shown.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

can you post the content you are trying to eval? i.e. the data stored inside $msg.
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post by Archy »

OK, sure, I am just testing it at the moment, so I do not have the actual code I am going to use in the end, but here it is that im trying to show:

Code: Select all

<html>

<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Test</title>
</head>

<body>



<div align="center"><?php echo"test"; ?></div>


</body>
Post Reply