PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old July 26th, 2004, 04:27 PM
Antnee Antnee is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 8 Antnee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Dynamic Sites and Templates

Hello again guys!

I'm still strugling along with my PHP/MySQL site and I've hit what appears to be a bit of a snag. I use a simple page as a template and call the content from the DB, however I only seem to be able to call HTML, not more PHP, am I doing something wrong?

Here is the basic end of the code:

PHP Code:
<?php
   
include("../connect.php");
   
   
//get user info from database using info passed from previous pages
   
$sql "SELECT * FROM verify WHERE username='" $_SESSION['user'] . "'";
   
$query mysql_query($sql);
   
   while (
$row mysql_fetch_array($query)) { 
   
       
$_SESSION['admin'] = $row['admin'];
       
   }
   
   
//now get the content for the page
   
$sql "SELECT content FROM verify_admin WHERE section='" $_GET["section"] . "'";
   
$query mysql_query($sql);
   
   while (
$row mysql_fetch_array($query)) { 
   
       
$content $row['content'];
       
   }
   
   
//check user is logged in and an administrator and refer elsewhere if not
   
if ($_SESSION['loggedin'] == '1') {
       if (
$_SESSION['admin'] == '1') {
           if (
$section == '') {
             echo 
"LOGGED IN<br/>Admin Account: Yes<br/><br/>" ?> <a href="admin.php?section=1">Proceed to Main Menu</a><?php ;
               }else{
             echo 
$msg"</font><br/>Welcome to Section "$section"<br/><br/>";
   
   
//Now the important bit, display the dynamic content
   
echo $content
   
           
}
           }else{
           echo 
"You are logged in but you do not have Admin rights";
       }
       }else{
   
   
//the log-in page
   
include("index.php");
   }
   
mysql_close($connection);
   
?>


Does that make sense? I know I'm a bad coder (either old habits or just being new) and I know the IF/ELSE statements are seriously untidy but I cannot get the content which is held in the $content variable to display PHP, only HTML!

Help!

Reply With Quote
  #2  
Old July 26th, 2004, 05:08 PM
Antnee Antnee is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 8 Antnee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Some users on other forums have suggested I try using eval() to execute this code but seems this is not recommended? Also doesn't seem to work!

Reply With Quote
  #3  
Old July 27th, 2004, 03:10 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 5
Out of curiosity why do you wish to get php code from a database? Could you elaborate on what it is you are trying to achieve and we might be able to give you an alternative even if we can't solve the actual problem.

-KM-

Reply With Quote
  #4  
Old July 27th, 2004, 12:22 PM
Antnee Antnee is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 8 Antnee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I'm trying to make a completely dynamic site where almost all code can be edited via a web-based admin tool. It's easier to do this if the whole thing is stored in a database.

I have thought about using frames or iframes to remedy this, purely because of the template. I'll make another page to go inside the frame. Will probably be the best idea anyway as the admin tool is in a fixed size window with no scroll bars so the iFrame could add the scroll bars I need... Hmm

Reply With Quote
  #5  
Old July 27th, 2004, 01:07 PM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 5
A database isn't the only way to have dynamic content. There's no reason not to store it in a normal file and provide a way to edit the file, which can then be displayed in a separate frame or window etc.

-KM-

Reply With Quote
  #6  
Old July 27th, 2004, 02:57 PM
Antnee Antnee is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 8 Antnee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I know, the way that the site works is that there is an ID passed via the URL, eg index.php?id=1

The id refers to part of the database which then pulls the information out and creates the page. The idea is that the page can be easily edited from another webpage. If there is another way to do that I would much appreciate advice on how to do it. Plus if I change the template the whole thing changes, not just a page. This appears to be the easiest way I have found to do this, as long as I only want HTML pages

Reply With Quote
  #7  
Old July 27th, 2004, 07:54 PM
Pheifel Pheifel is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Denmark
Posts: 174 Pheifel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 46 sec
Reputation Power: 5
Send a message via MSN to Pheifel
make sure, that e.i. $ are \$ so they will be stored correctly and displayed correctly ??

- pheifel

Reply With Quote
  #8  
Old July 28th, 2004, 02:43 PM
Antnee Antnee is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 8 Antnee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
These are OK. If you look at the code on one of the pages in a web browser you can still see the PHP code, it has not been processed by the server. I have been onto the host and have learnt that this is by design, I just need to find if there is a way around it!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Dynamic Sites and Templates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway