Current location: Hot Scripts Forums » Programming Languages » PHP » Need help with "nested" PHP

Need help with "nested" PHP

Reply
  #1 (permalink)  
Old 07-04-09, 09:30 AM
fahuber3 fahuber3 is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Question Need help with "nested" PHP

Currently I have a website that contains one php page and based on what the user selects from the pull down menu, that is what gets populated on the page from a MySQL database. The code works perfectly unless I need to
PHP Code:
<?php                            
        $value 
$_GET['page'];                        
            
        
$connection mysql_connect(localhost"ID""PW");
        
$db mysql_select_db("DB") or die( "Couldn't select database");
        
$sql "SELECT * FROM site WHERE page_id = '$value'";
        
$mysql_result=mysql_query($sql,$connection);
        
$num_rows=mysql_num_rows($mysql_result);
        
                    if (
$num_rows == 0){
                            echo 
" ";
                    } 
            
                    else {    
                        while (
$row=mysql_fetch_array($mysql_result)) {
                                
$pagename=$row["pagename"];
                                
$content=$row["content"];

                        echo 
"<h1>$pagename</h1>
                                $content"
;
                        }
                    }
                    
                
mysql_close($connection);
                
?>
I want to be able to store another php script in the $content from my database so that it is called when the user selects the page. No matter what I have tried, the php does not work and instead it prints the php code.

Is there anyone that can point me in the right direction please?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-04-09, 12:11 PM
wirehopper's Avatar
wirehopper wirehopper is online now
Community Liaison
 
Join Date: Feb 2006
Posts: 2,326
Thanks: 17
Thanked 92 Times in 90 Posts
If there is PHP in the database, you'll need PHP: eval - Manual to execute it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-04-09, 03:16 PM
fahuber3 fahuber3 is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
I tried storing just this in the content field in MySQL but when it is called, it just prints it to the screen.

mixed eval ( string $select id, teamname from team where a_flag = 'A' order by teamname )
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-04-09, 03:52 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 414
Thanks: 4
Thanked 27 Times in 26 Posts
Is your php page named with a .php ext. ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 07-04-09, 04:23 PM
wirehopper's Avatar
wirehopper wirehopper is online now
Community Liaison
 
Join Date: Feb 2006
Posts: 2,326
Thanks: 17
Thanked 92 Times in 90 Posts
Try something like this:

PHP Code:
<?php
echo 'Test from database';
?>
Store it in the database, then use:

PHP Code:
echo eval($content); 
to display it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 07-05-09, 08:50 PM
fahuber3 fahuber3 is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
I return eval( )
using the following code in my php file
PHP Code:
echo "<h1>$pagename</h1>
        eval($content)"

and storing
PHP Code:
<?php
echo 'Test from database';
?>
in the content field
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 07-05-09, 08:57 PM
wirehopper's Avatar
wirehopper wirehopper is online now
Community Liaison
 
Join Date: Feb 2006
Posts: 2,326
Thanks: 17
Thanked 92 Times in 90 Posts
PHP Code:
echo "<h1>$pagename</h1>";
echo eval(
$content); 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 07-05-09, 10:59 PM
fahuber3 fahuber3 is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
I now receive the following error message on my page:


Parse error: syntax error, unexpected '<' in /home/uoszpb/public_html/nav.php(69) : eval()'d code on line 1
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 07-06-09, 12:25 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 2,726
Thanks: 0
Thanked 32 Times in 32 Posts
The PHP code in the database must not have opening and closing PHP tags,
just the raw PHP code.
And any HTML must be echoed.

Example:
The code in the database could look like this,
notice that there are no opening or closing PHP tags.
PHP Code:
echo "<p>Hello World.</p>"
Then your code will work.
PHP Code:
<?php
        $value 
$_GET['page'];
        
$host "localhost";
        
$user "ID";
        
$password "PW";
        
$db_name "DB";
        
$connection mysql_connect($host$user$password);
        
$db mysql_select_db($db_name) or die( "Couldn't select database");
        
$sql "SELECT * FROM site WHERE page_id = '$value'";
        
$mysql_result=mysql_query($sql,$connection);
        
$num_rows=mysql_num_rows($mysql_result);

                    if (
$num_rows == 0){
                            echo 
" ";
                    }

                    else {
                        while (
$row=mysql_fetch_array($mysql_result)) {
                                
$pagename=$row["pagename"];
                                
$content=$row["content"];

                        echo 
"<h1>$pagename</h1>";
                        eval(
$content);
                        }
                    }

                
mysql_close($connection);
                
?>
__________________
Jerry Broughton

Last edited by job0107; 07-06-09 at 12:27 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 10:17 AM
help with error messages.. please APuppyDog PHP 2 10-05-06 11:09 PM
PHP Downside--Solutions? Amulet PHP 10 07-15-05 08:26 AM


All times are GMT -5. The time now is 08:13 PM.
vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.