I am doing the group assignment that involved in using HTML, CSS, JavaScript and PHP. I am using seperated HTML, then send the form data to a seperated PHP file to handle. But the more i learn about PHP, i feel that i can use pure PHP file to contain HTML data too, more convenient.
For example: i have a html file login.html, it has one <form>
element inside the body to login. The form use POST
and it leads to processLogin.php
Should i process them seperatedly or to use single processLogin.php that contain a form and contains the php scripts too ?
CodePudding user response:
Mixing languages is not a good idea. Because different languages usually correspond to different layers.
PHP deals with business logic. HTML deals with presentation of the business objects. Thus, you have two layers: the one generates the objects; the other one builds a pseudo-XML representation of those objects.
In the same way, JavaScript deals with interaction, and CSS with the presentation of the content. When you want to change interaction, you don't open an .html file, and you surely don't open a .php file: you open a .js or .coffee file.
Note: extracted form other answer. You can read the full answer here.
Now, my opinion. For a small project u can use together, but if want a robust project try use the MVC pattern. The main aim of MVC Architecture is to separate the Business logic & Application data from the USER interface.
CodePudding user response:
it would be better to separate them, write the html in one file and php in another file, so that will be easy if you want to change something in php code or html, the same for css and js it would be better to write everything separately...