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

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

PHP not executing

Post 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.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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.
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post 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.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Code: Select all

<?php
echo (eval($code));
?>
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post 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.
Last edited by Archy on Tue Nov 02, 2004 3:15 pm, edited 1 time in total.
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post by Archy »

The code can be found here: #N/A
Last edited by Archy on Tue Nov 02, 2004 3:16 pm, edited 1 time in total.
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post 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.
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post by Archy »

All sorted, thanks for all your help.
: )
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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

Code: Select all

eval($str);
echo($str);
That is unless you want them to be able to view your source.
Post Reply