I have a basic page. It is a user registration page. Can i possibly create a ‘register.php’ page that will layout the HTML skeleton, CSS to dress the page up with styles, javascript to give it a cool effect and more other interactive kicks and PHP simply to store the user registration information to a database?
Or is that not recommended? I was reading a book called “PHP & MySQL in easy steps” by Mike McGrath The BOOK. This book literally gave a PHP file as well as a CSS, HTML, JS, and MySQL all separate files. I understand that for an OOP it is best to keep everything on its own. But for sake of learning and producing my own code, everything can be on the same php file except the database, correct?
Also is that the purpose of PHP in the above case? To use it to store and retrieve user information and send it to the a database for storage until its needed again?
I understand how to code and program (electrical engineering background in C/C++, etc.) however i don’t seem to understand the real purpose of using PHP?
Yes, it is possible to put all that code in one file, but it is highly recommended that you keep as much of your css, javascript, php and html all in separate files, even if you are not using OOP.
Basically the PHP code in this case is used to ‘communicate’ with the database and return from the database dynamic information that can be sent to the browser as html, such as a success message forthe registration.
I understand how to code and program (electrical engineering background in C/C++, etc.) however i don’t seem to understand the real purpose of using PHP?
One feature of the Php language is to be able to read, write and manipulate data from numerous file types and popular databases. Selected data is then wrapped in HTML tags suitable for browser rendering.
As far as Php including files they should be treated similar to C/C++ functions. If a script is used more than once a function is essential to prevent error prone code duplication, code bloat, easier maintenance, readability, etc
Frequently it is beneficial to include file contents to reduce Http requests, which are detrimental to a page speed loading time.
That makes senses, however, how do i link a php file to an html? Or are you refering to using the include keyword to include php into html/vice versa? I still havent looked at include because that seems to be further within the chapter. I learn best by applying what im reading into a scenerio i find myself coding!
With this login page im creating, i decided to create a simple HTML login page that will include all login features. I then added an external CSS that will decorate the site and arrange anything and everything. I’m debating on whether to add javascript to give the login page some form of effect such has underlines hover, etc. However, i added the ‘action=“file.php”’ to the html form. I’m assuming that whenever the user does some form of event handling within the form, all the information will be sent to the php file.
The PHP file will then store whats necessary and provide validatio as well as access to the site if everything is correct from the user. However, does the php file need to include HTML in itself or can it be purely php code?
Its all theoritical, since i havent started coding the login page. I prefer to plan everything out before jumping into it! Makes life easier !
a php page will output html to the browser but be parsed by the server as php. So any php code will run before the page is served to the user as a complete page. You don’t necessarily need to put any php code on a .php page you can just have an entire page of ‘html’ served via a .php page.
There are certain php features you will want/need for login scripts as you will probably want to set session variables or cookies and be able to read them and interrogate a database to check they match. You can’t do that will a .html page.
Unlike JS, php is a serverside language so (unless you use ajax) for something like a form selection you have to submit the page to the server to be processed and returned if you want to run a php function. JS would be able to manipulate page elements without page reload but would require those elements to already be loaded. Ajax is a mix where JS is used to get a php page to return elements into a page without reloading.
hope that makes some sense (others please correct me if i have put bad info but that is my understanding)