Copy and paste php in an existing html page

12 posts by 3 authors in: Forums > CMS Builder
Last Post: April 22, 2010   (RSS)

By trickster - April 21, 2010

Hi,

I don't profess to be a code writer. I have built several websites in html and they have worked fine. I can even fake it for some of the basic coding by editing, cutting and pasting.

I am somewhat disappointed by the level of difficulty which your product seems to require. I have been struggling with adding your code generator code to my clients existing site. Your advertising sounds easy, but I am here to tell you it isn't easy. I don't want to have to ask for a refund, but I will have to soon if I can't get this to work.

I noticed a forum posting that stated problems with php in an existing html site. Is this true? Is that why I am having soo much trouble. Your literature doesn't state that you have to start using your software with a new php only site. I would like to know if I need to be a programmer to use your software or is it a software problem.

Thanks for your prompt reply

Re: [trickster] Copy and paste php in an existing html page

By Dave - April 21, 2010

Hi trickster, welcome to the CMSB forum! :)

What is the specific problem you are having or error you are getting?

For an existing site you do need to either change the extensions to .php or tell your webserver to treat .html files as .php files:
http://www.interactivetools.com/docs/cmsbuilder/file_extensions.html

You don't have to be a programmer (most people in the forum aren't), and it is very easy compared to any other method of building a custom CMS, but you still may need to give yourself some time to get familiar with it.

Start with small steps, I'd recommend getting a test script like this working on your server first:
<?php
# save this file as hello.php
print "Hello World from PHP";
?>


Then saving the generated viewer code with the recommended .php filenames and getting that to display properly, then work on integrating that with your existing html code but with a .php extension (so your existing pages aren't modified until you are ready).

Hope that helps. Keep us up to date with your progress!
Dave Edis - Senior Developer
interactivetools.com

Re: [trickster] Copy and paste php in an existing html page

Hi Trickster,

Creating your first CMS pages can seem confusing in the beginning, but you'll get the hang of it soon. Once you do, you'll be amazed at the ease and flexibility CMSB offers.

You will probably want to change the extension of your pages that use PHP to .php instead of .htm or .html. This tells your server that you want the page treated as a PHP page and to pull your content information from your database. (There are ways to instruct your server to do the same with .htm and .html, but for now it's easier to change the extension.

You can run any combination of html and php pages on your site, but pretty soon I'll bet you'll be switching them all.

One major difference between HTML hard coding and CMS, is that with CMS the information displayed on the page is pulled from fields in either one, or a number of database tables (sections) that you create.

Those database tables can each contain of either one record (a single record database table (for an about us section for example), or a series of records in a multi-record table (a list of videos for example).

Let's get started creating your first page

In, in your admin area under section editors, create a simple single record editor and call it Index.

Then go to the menu of existing sections (left side of the admin page) and click on the new "Index" section that you just created.

Add some information in the fields provided, and save the record.

Now go to the code generator in the admin section and choose the Index section, and the Detail page radio button.

Paste the code generated into a blank web page, name it indextest.php and upload it to your server.

Notice where the various pieces of information appear on the viewer page and compare it to the code of the page.

You can add any fields you like to the editor, re-generate the code, and place the code snippets anywhere on your page that you'd like.

Once you get the hang of this, try inserting the code at the top of the page into your real pages, and then inserting the appropriate code snippets where you want the fields (pieces of information) to appear on your page.

It may take a bit of getting used to, but once you understand the concepts behind CMS, there's virtually nothing that can not be done with CMSB.

Hope that gets you started,

Best,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Copy and paste php in an existing html page

By trickster - April 21, 2010

Hi,

Thanks for your reply.

Soo, I am able to see the php code generated as a page in a browser. Then when i try to copy and paste it into my existing page I run into problems. I guess I don't quite understand how it all works. If i copy and paste into my existing page, then edit the code using frontpage, am I destroying the link between the saved file (example: newslist.php). It is my understanding that whatever i do for edits should probably be done in the original file that I create in csm builder. When i generate that code, i am stuck with it, unless i go back into csm builder and change and regenerate it... is this true.

I am trying to make my clients website updateable by them. I need to know that whatever i create and copy paste into the existing website... that it will reflect any changes they might make as an editor.

This is a hell of alot harder than it you guys make it out to be.

Thanks for your help

Re: [Dave] Copy and paste php in an existing html page

By trickster - April 21, 2010

Hi,

I'm not sure what you wanted me to do with this code:

<?php
# save this file as hello.php
print "Hello World from PHP";
?>


I copied it into a simple text program, saved it as a php extension and uploaded it to my root file directory.... i got nothing.

I have had success with the code generator and pasting code into a simple text doc with a php extension. The above code you wrote should work in theory, but when i save it to the directory on my server and type mydomainsurl/hello.php... I get nothing.

A question another user had raised, questioned the changing of the files on my server from html to php. He stated that this would render all the search engine links that exist presently, null and void, due to the change in file name. This is true is it not? Is there any way around this?

Am I going to have lots of problems embedding the php code into my existing webpages if i don't change them to php extensions?

Thanks

Re: [trickster] Copy and paste php in an existing html page

By Dave - April 21, 2010

Hi Trickster,

>If this is all over my head, then just say so.

With all respect, I would say that right now it probably is, so if you choose to continue you're going to take this on like any other new technology that you may have learned such as CSS, photoshop, etc and give yourself a lot of time and patience.

If you are in a rush and need a solution ASAP this probably won't work for you. if you want a completely automated solution it also won't work for you. But if you are able to learn it you'll be amazed at the things you can do with the software.

A couple of tips:

- You're going to need to figure out how to get your editor to allow you to copy and paste PHP code and have it work when you upload it. Go through the settings or search online for tips. Almost all web editors made in the last decade support PHP tags, but some need some settings adjusted so they don't automatically wrap lines, etc.

- The next step is to get that hello.php script working. Being able to upload a test php script and getting it to run on your site is a pre-requisite for being able to use the software.

- Next, you'll need to be able to hand code HTML to use this tool. That's also a requirement so make sure you can do that.

And some answers:

Re: changing page extensions - Yes, you'll need to either name the pages PHP or use the tip I previously gave you to have your web server parse .html files as .php. And yes, some of the filenames will change. There's no easy way around this (there's some complex ways), if you're moving from a hand-coded solution to a CMS (any CMS) the urls are going to look at least a little different. The default url format we use is optimized for SEO, though, with keywords in the URL so you could end up with better rankings.

The "Cannot modify header information" error means you put something before your first PHP tag. make sure <?php is the very first thing in the page or attach the index.php file to this thread with "Upload Attachment" so we can take a look and help.

For now you will need to upload the files your website to see them. And yes this can be more time consuming. You usually make this time up during content-entry and when creating multiple pages (since new "pages" are created by the CMS.

>It has been suggested that I buy your cms cookbook

I know some users really love the cookbook, but it's not by us and there's no expectation that you buy it.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Copy and paste php in an existing html page

By trickster - April 22, 2010

Hi,

can you look at this and tell me why i am getting the error. I have tried placing the php code in multiple places and always seem to get an error.

"Warning: Cannot modify header information - headers already sent by (output started at /hsphere/local/home/elsareim/emmanuelshepherds.com/index.php:27) in /hsphere/local/home/elsareim/emmanuelshepherds.com/index.php on line 102"

Thanks

Re: [trickster] Copy and paste php in an existing html page

By trickster - April 22, 2010

sorry, forgot the file.
here it is, thanks.
Attachments:

index_013.php 15K

Re: [trickster] Copy and paste php in an existing html page

By Dave - April 22, 2010

Hi trickster,

Try removing this content from the middle of your page (starting on line 102):

&nbsp;<?php header('Content-type: text/html; charset=utf-8'); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<style type="text/css">
body { font-family: arial; }
.instructions { border: 3px solid #000; background-color: #EEE; padding: 10px; text-align: left; margin: 25px}
</style>
</head>
<body>


And also remove this around line 28:
</body>
</html>


Your html document already has a header and footer so you don't need to copy and paste those parts again.

Let me know how it goes.
Dave Edis - Senior Developer
interactivetools.com