Page 1 of 1
PHP not executing
Posted: Tue Nov 02, 2004 2:12 am
by Archy
I need to insert some code into a MySQL database, so a friend of mine can make a couple of pages for his Uni project. However, the PHP that he insert's does not get executed on the pages that output the code from the database. Does anyone know how I can solve this?
Thanks.
Posted: Tue Nov 02, 2004 3:16 am
by phpScott
show us some code so we can see what he is trying to do it could be anything from syntax to a logic problem.
Posted: Tue Nov 02, 2004 9:43 am
by Archy
Well, it's just standard code...
Update code page (Snipped)
Code: Select all
<?PHP
...
if($update != ""){
$sql = "UPDATE site SET 1='$page1' WHERE id='$update'";
$rs = mysql_query($sql) or die(mysql_error());
}
?>
</HEAD>
<form action="index.php?update=1" method="post">
Question Page 1:<br />
<textarea rows="20" cols="90" name="page2"><?PHP echo"$code2"; ?></textarea>
<br />
<input type="submit" value="Update" />
</form>
...
And the show page...
Code: Select all
<?PHP
...
$sql = "SELECT * FROM site WHERE id='1'";
$rs = mysql_query($sql) or die(mysql_error());
$get = mysql_fetch_assoc($rs);
$code1 = $get['1'];
echo($code1);
?>
As I said, pretty standard. I remember hearing somewhere that PHP doesnt like being parsed as it comes out of a MySQL database, however, I cant remember where I heard it to : (
Thanks.
Posted: Tue Nov 02, 2004 12:52 pm
by josh
Posted: Tue Nov 02, 2004 1:16 pm
by Archy
That was it, although I'm coming out with an error :\
Parse error: parse error, unexpected '<' in /home/chris/public_html/med/Firstpage.php(11) : eval()'d code on line 1
The exact code I am using to parse the code is:
Code: Select all
<?PHP
$conn = mysql_connect('localhost', 'username', 'password') or die(mysql_error());
$rs = mysql_select_db('database', $conn) or die(mysql_error());
$sql = "SELECT * FROM site WHERE id='1'" or die(mysql_error());
$rs = mysql_query($sql) or die(mysql_error());
$get = mysql_fetch_assoc($rs);
$str = $get['1'];
eval($str);
echo($str);
?>
Thanks.
Posted: Tue Nov 02, 2004 1:39 pm
by rehfeld
and what is the output of echo $str?
the code your trying to eval has a parse error. you should treat it like any other parse error.
most likely your str has a <?php tag in it, which you need to remove
see the examples on php.net/eval
Posted: Tue Nov 02, 2004 1:43 pm
by Archy
The code can be found here: #N/A
Posted: Tue Nov 02, 2004 1:45 pm
by Archy
rehfeld wrote:most likely your str has a <?php tag in it, which you need to remove
It does, and that is the point, I need to find a way to output the PHP as well, without causing an error.
Posted: Tue Nov 02, 2004 3:16 pm
by Archy
All sorted, thanks for all your help.
: )
Posted: Tue Nov 02, 2004 3:51 pm
by josh
The echo function just outputs text to the browser, such as html and stuff, the eval function runs the code.... if the code you run has an echo in it, it will print out like normal so there is no need to eval the variable then echo it you can just eval it...
I am refering to the lines
That is unless you want them to be able to view your source.