ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am trying to create a site that will be easy to use for the administrator of the site. My current idea is to have certain pages stored in the MySQL database with all the html and so on, which will be editable through forms on the side itself.
The problem is that I want to be able to use php code as well. For example, I have a string "<div>here is some php <? echo \"asd\"; ?></div>", this is then stored in the database, and will be editable for the admin. The problem is: how can I insert this into the page, using PHP, but still make the server run the php code? A simple 'echo $code' won't work obviously. I have looked at eval() but that would require me to use ONLY php code and get rid of all the html.
I don't think PHP has a way to do what you want. But why are you using a database? If it was files, you could just use "include" or "require". The only way I can think of would be to read the page from the database, write it to a disk file, and then use require.
Maybe there's another way, but I think it would be complicated. Why not use just files?
Well I have been thinking about using files instead. It's just that I would like it if I can change the content directly on the site itself. I guess I can accomplish this by saving and reading from files. Guess I'll have to work with it that way.
i considered doing this exact same thing before.. and the only answer i could come up with was..
* read the page from the db
* write the data from db to a new file
* redirect the browser to the new page
* after user leaves page delete the file
seemed like alot of work and it still did not really do what i was hoping for..
however it is a good idea, and could be pretty useful.. though you could just give an admin access to modify the necessary files..
Well I still need the db since I do not only have the html in there but also the hiearchy of the different pages for navigation. But what I did was that I have created a "edit pages"-page which takes an id of a page as argument, fetch all data from the db and opens the file page/<i>name</i>.src and put the content in a textarea. When the user submits I just update the db with the navigation data and update the file with the new content. So the html never touches the database actually.
This way I can give the admin a choice of either edit the pages in the site, or by modifying the files in the page-directory. The reason why I want to have the editing aviliable on the site itself is mostly because the admin after me is not familiar with *BSD or anything other the Windows actually. And I thought it would be easier for both me and him to just put all the content on the site, instead of requiring him to learn how to navigate and edit files in a UNIX environment.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.