PHP coding being commented out by the HTML editor

Permalink
I want to connect an existing single-page to an existing MySQL database that is currently accessed by another page (the "Readings" page) in the site. I should mention that the rest of the site was NOT created using Concrete5 (nor any other CMS) and that the Concrete5 directory is located within the main directory of the web site. The single-page is accessed bywww.www.sitename.org/Concrete5....

The "Readings" page (www.sitename.org/Readings) in the site shows a daily reading which is provided by the MySQL database mentioned above. This page uses the PHP mysqli_connect function to access the database.

From what I have read in the documentation, I need to use a single-page in order to use PHP code to access a MySQL database other than the database that generates a Concrete5 page.

I tried to edit my single-page by creating a block and using the HTML editor to write the appropriate PHP code. However, when I checked on the block after using the HTML editor, it came up empty. Going back into the HTML editor, I found that my PHP code had been commented out. For example, <?php echo("Hello World!"); ?> would be changed to <!--?php echo("Hello World!"); ?-->.

How do I get Concrete5 NOT to comment out my PHP coding and hence the mysqli_connect function?

 
mhawke replied on at Permalink Reply
mhawke
HTML is rendered client-side and PHP is done on the server.

You need to hard-code your database open/read/write code into the single page itself or better yet, build it into a controller file.

To use a separate controller for a single page that resides in your '[root]/single_pages' folder, you add an identically named file in the '[root]/controllers' folder so if your single page is '[root]/single_pages/my_single_page.php', you should have a file by the same name in '[root]controllers/my_single_page.php'. This controller page is where you put the I/O functions that deal with your database.

Have a look at this CRUD package on GitHub. It might give you some ideas on how to approach this:

https://github.com/jordanlev/c5_boilerplate_crud...