What is PHP and how do you link/use it in web development?

pompa pomp

New member
What exactly can you use PHP for? What i understand is that you can read and write information on a database. Is it like javascript and css where you link your PHP file with a source code in your html page?
 
Yes, good answers so far.

I just wanted to add that PHP allows your websites users to interact with your web-server in ways that you choose. An example is web-server that has a user database.. so users can log in to your site and access certain features like retrieving information and updating their login settings, post messages to a forum, use a simple chat box.. or anything you can think of.

A PHP file will generate HTML output like form fields, tables etc (indeed anything that you would typically see on a HTML web-page). This HTML output is then sent to the users browser. So the user doesn't actually get to see the PHP file in it's original form -- but only the generated HTML output. The user can then fill in form fields, click buttons etc and data is then sent back to the web-server... where it is either handled by a different section of the same PHP file, or it is redirected to a different PHP file. The receiving PHP file takes this user input and queries it against a database (or server side data files - i.e. text files). The results of these queries are used to update the database/data-files and/or to generate new output which is sent to the users browser (again usually in HTML format). This way there is a 2 way interaction between the PHP files on the web-server and the user via his or her web-browser.

But a PHP file can do more than generate HTML. It can also generate Javascript alongside HTML. This is useful for implementing enhanced features on the client side such as client-side validation. Trust me.. when you are writing PHP code that generates Javascript code alongside HTML.. you know you are having fun! :-) But this should be used with caution. Always remember that some people still don't have access to Javascript (either through choice or limitations of the browser). So Javascript should only be used for optional 'enhancing' features. Basically you don't want the web-page to break if user doesn't have Javascript enabled.

For development purposes you can install a web-server on your computer. This way you can test PHP on you own web-browser -- without the need to register with an online web-server that has PHP enabled. This is relatively easy to set-up using software such as Wampserver (if you have windows). For other operating systems there are similar free software packages, that are also relatively straight-forward to download and install.
 
PHP is server side programming and Javascript, CSS are client side. With PHP u can send information to database , retrieve it but u can't connect to database using Javascript and CSS. CSS is just for styling of webpages.
 
Back
Top