Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Wednesday, 29 August 2012

How To: AJAX PHP Functions

Using AJAX, you can combine HTML, JavaScript, PHP and XML to enhance websites. By adding AJAX PHP functions to your pages, you can create a more dynamic, interactive experience for your users. With AJAX, your pages can call a PHP script running on the Web server. This script can query a data source such as a relational database or XML store for new data. The script can then return this new data to the user's browser, where the client side script in JavaScript can write the new data into the page HTML. Essentially, this means that you can fetch and present new data to your users while they interact with your page, and without having to refresh the page as a whole.

Build the Page

Create an HTML page to implement your AJAX PHP processing. Use the following outline:

<html>
<head>

</head>
<body>

Here we will display new data from the server.
</body> </html>

We will place JavaScript functions in the page head area for fetching and receiving the new data from the server. Within the body, we have an element in which we will display the new data and a button to prompt the AJAX function execution.

Add JavaScript

In the script section in your page head, add the following code:

function getNewData() {
 
    //XML HTTP Request object
var xmlHTTPReq;
 
    //take care of different browsers
if (window.XMLHttpRequest) xmlHTTPReq = new XMLHttpRequest();
 
else xmlHTTPReq = new ActiveXObject("Microsoft.XMLHTTP");
 
}

Here we create an XML HTTP Request object. Next we provide the browser with instructions for when the new data is received, still inside the "getNewData" function:

xmlHTTPReq.onreadystatechange = function() {
 
//write the result to the page
if (xmlHTTPReq.readyState==4 && xmlHTTPReq.status==200)
document.getElementById("resultArea").innerHTML = xmlHTTPReq.responseText;
 
}

This code simply writes the new data to the section in the Web page with "resultArea" as its ID attribute. We have instructed the browser to handle the returned data, now we need to call the server side PHP script, at the end of the "getNewData" function:

//specify the script
xmlHTTPReq.open("GET", "get_data.php", true);
xmlHTTPReq.send();

Create a PHP Script

Next we need to create a PHP script to fetch the new data. Open a new file and save it "get_data.php" entering the following code:

<?php
$rand_num = rand(0, 100);
echo "Here is a random number between 0 and 100: ".$rand_num;
?>

The PHP script could do many different things here, such as fetching data from a database or from XML. In this case we simply return a random number for demonstration. Save your HTML and PHP files and upload them to your server. Visit the page in your browser and click the button to see the new data fetched from the server.

Options

You can also pass data to the PHP script if this suits your needs. For example, you can capture user data from an HTML form with input elements, passing the entered data for processing at the server side. A common use for this is committing the new user data to a database. To pass data to PHP, simply retrieve the user input data in the JavaScript function and append it to the PHP script URL as in this example:

//user entered data is stored in a var named "userData"
xmlHTTPReq.open("GET", "get_data.php?info=" + userData, true);

In the PHP script, you can retrieve the passed data as follows:

$passed_data = $_GET["info"];

Conclusion

You can incorporate AJAX PHP functions with various other technologies such as XML and jQuery. The emerging HTML5 features are also set to provide enhanced levels of communication between client and server using such utilities as Server Sent events, so the browsing experience is going to become more and more responsive.

See also:

Tuesday, 28 August 2012

Web Development Concepts: Client and Server

To put it simply, this is about the relationship between two computers: yours and the server. Client stuff happens on your computer and Server stuff happens on the server. However, although the Client stuff runs on your computer, it's still stored on the server. Make sense? Let's explore it in a bit more detail.

Who's Who

The terms Client and Server are used in Web development contexts. As with all tech terms, these are often used as a concise reference, but are unfortunately also often used when another term would actually be easier to understand. For whatever reason, a lot of geeks seem to love using mystifying language, perhaps to compensate for their crippling social inadequacies (and I include myself in that category) - who knows?

Anyway, Client and Server are fairly easy to get to grips with. They simply refer to where the different functions of a website are run. Server refers (as you might have guessed) to code etc that is executed on the Web server, and Client refers to things that happen within the browser (e.g. Firefox, Internet Explorer, Opera, Safari, Chrome) as it runs on your computer.

The Network

The terms Client and Server are used to reflect the relationship within the computer network (i.e. the Internet). However, you don't need to understand the ins and outs of networking to understand these terms.

The Process

When you browse to a website, a number of things happen. The data and programming code etc for the site are stored on the Web server. The website address identifies the location of the server, and the browser requests the relevant page from this location.

The Web browser receives the HTML content from the server, which it is able to interpret and display as a Web page, together with the text, images, data etc and style rules determining how it should be displayed.

A wide variety of technologies are used in Web development, some running on the server, and some on the client. Your Web browser is basically able to display HTML, but this HTML may be served to it in different ways.

Models

The traditional Web model meant storing HTML pages on the server which are simply sent to the browser and displayed. In this model, the content of a site was all directly written into the HTML files, and had to be manually changed if the information needed changed. However, as sites developed, there became more of a focus on data-driven sites that are said to be 'dynamic'. This simply means that the sites use data and other resources to build the Web pages at the time that they are requested by a browser.

Server side programming is one of the main tools involved in this. Server side languages such as ASP and PHP run on Web servers, creating HTML when they run and sending it to the requesting browser to be displayed. In a typical model, the Web server will have a database on it, plus the other content such as images etc. When someone requests a page, the Server side scripts execute, query the database for any relevant information and write this back to the browser in the form of the HTML page.

Client side programming refers to functionality that is carried out within the browser itself. Many sites try to be interactive in different ways, and one such way is using a Client side language such as JavaScript. This is typically used to achieve things like interactive menus and styles that make the elements in a site change their appearance as you interact with them using your mouse and keyboard - these are generally carried out using CSS (Cascading Style Sheets).

With the emerging techniques in HTML5 and CSS3, websites are becoming even more responsive, interactive and dynamic from both client and server side.

Client and Server Working Together

Some uses of Web technology use the two approaches of client side and server side development in tandem, such as AJAX, as well as many jQuery and HTML5 functions. You'll see examples of these on lots of sites, where an element of the page is updated without the page as a whole being refreshed. In this case a Client side script in JavaScript often sends a request to a server side script (e.g. in PHP), with the returned data displayed in the browser without it having to request a new page. With HTML5, the client side code doesn't even have to request something from the server, the sever can simply push new data for the browser to display.

Usage

If you see someone referring to Client Server Applications or Client Server Development etc, this is really just a reference to the use of a variety of technologies deployed both on the Server and Client. These days, Web development pretty much always involves both so the terms are often redundant. Some developers do specialise and focus on one side or the other, particularly where large Web applications are involved.

Relevance

If you are planning to get involved in Web development yourself, it is vital to understand the process that executes when people view websites. However, if you are only planning on accessing the Web as an end-user, you really don't have to understand these concepts, although they are interesting if you're an utter geek like me.

See also:
What is Dynamic Content?
What is Web Content?
How to Get Started with Web Development

Monday, 27 August 2012

How To Send Mail In PHP

PHP code can send email messages without the need for site administrators to handle them manually. When Web developers build sites and applications, they can opt to send email messages as part of this processing. If you have ever signed up to a website or online service, you may have received an email confirming your account details. These emails are often not sent manually by a person using a standard email client, but by automated scripts. In PHP scripts, you can use sendmail functions to implement this process, which is common in server side scripting.

Purpose

The purpose of sendmail scripts in a PHP site is to send email messages. The sendmail functions allow developers to build email messages in HTML or plain text, then to send these messages to specified recipients.

PHP scripts can set various properties of a message before sending it, including headers, titles, lists of recipients to copy to and the content itself. Often, developers define individual mail scripts dedicated to sending standard email messages for set processes, such as confirming user accounts.

When a PHP script actually sends a message, it can use the mail function. If the recipient chooses to reply to the message, their reply will be sent to the specified "from" address in the script. Using the headers section of the function, developers can include multiple aspects of the message, including MIME and content type.

Syntax

When developers implement sendmail scripts, they use the mail function, which offers a range of options. The following sample code demonstrates calling the function inside a PHP script:

<?php
$mail_to = "person@somedomain.com";
$mail_subj = "Hello";
$mail_msg = "

This is the content of the email message

"; $mail_frm = "sender@somedomain.com"; $mail_head = "MIME-Version: 1.0\r\n"; $mail_head .= "Content-type: text/html; charset=iso-8859-1"; mail($mail_to, $mail_subj, $mail_msg, $mail_head); ?>

The mail function can receive four parameters, representing the email address to send to, the subject of the message, the message body and any headers the script is setting. This script builds each of the component parts as individual parameters, then passes them to the function when it executes.

Uses

Sites use PHP mail functions for various different purposes. Managing user accounts is a common activity in which sendmail scripts tend to feature, not only for signing users up with new accounts but for account administration actions such as changing passwords and informing users of changes to accounts. Commercial websites also use server side scripts to send automated emails to customers, for example to confirm purchases, payments and dispatching of products.

Considerations

The PHP sendmail functions provide a degree of flexibility for developers. For example, scripts can send HTML formatted mail rather than plain text. However, developers need to consider the email clients and other environmental factors for their users. For example, some HTML email content may not be visible to users on certain platforms. Developers also need to bear in mind the fact that users may be receiving their messages on mobile devices with restricted display and connectivity. For this reason, some developers keep the formatting and content of automated emails as simple as possible.

See Also:
How To: AJAX PHP Functions
How To: JavaScript PHP Function Calls

Monday, 20 August 2012

How To: Javascript PHP Function Calls

Calling JavaScript functions from PHP is a common task in Web development.

When you build the HTML content of Web pages in PHP code, there are likely to be times when you need to call JavaScript functions. In dynamic websites, it is not unusual for pages and scripts to contain PHP, JavaScript, HTML and sometimes other types of code such as CSS, so the development process can become confusing. However, by building each of the elements in your website pages one at a time, then working out how to coordinate them, you can integrate the technologies with no trouble.

Before You Start

When creating a Web page containing JavaScript, PHP and optionally other languages, as well as implementing the interaction between them, it's good to first make sure you have a clear idea of the order in which the parts of your page are being constructed. If your PHP code is building HTML then writing this to the browser, your JavaScript function calls will need to be contained within these HTML structures.

JavaScript PHP function calls are dealt with at the same time when you write your scripts. However, when your pages are actually visited and interacted with by users, the two aspects of functionality are not executed at the same time. Don't worry if you still find these concepts confusing, as the best way to get to grips them is by putting them into practise. Learning to combine PHP with JavaScript is a good exercise to equip yourself with basic Web development skills.

Page and Script Outline

Within PHP files you can alternate between HTML and PHP code. Create your basic Web page outline as a PHP file containing HTML structures, as follows:

<html>
<head>
</head>
<body>
<?php
//PHP code goes here
?>
</body>
</html>

Copy the code into a new file in a text editor and save it with ".php" extension, for example "yourpage.php" - reflecting whatever the page content is.

Insert Your JavaScript Function

Add your JavaScript function. You can include JavaScript in a separate file called from the head of your page as follows (between the opening and closing head tags):



Alternatively you can include the JavaScript code directly within the page head section as follows:



This function is for demonstration, but you can include whatever function you intend to call from your PHP code.

Call JavaScript From PHP

Insert your PHP code within the PHP section of your page, as in this example where a series of buttons are created:

<?php
$count;
for($count=0; $count<10; $count++)
echo "<input type='button' value='button ".$count."'
onclick='yourFunction(".$count.")' />";
?>

Each button is given a number, so you will be able to see whether the script is working at a glance. Notice that in the section of code where PHP is writing out HTML, both single and double quotation marks (inverted commas) are being used. This is to distinguish between the PHP and HTML content. Double quotes are used within the PHP to delineate parts of the code to send to the user's browser, and single quotes are used within the HTML that is actually sent.

Upload and Test

Upload your page to your Web server. Browse to the Web page in your Web browser and test to see whether it works. Click on each button in turn - you should see an alert dialog box pop up, demonstrating that the JavaScript function is being called, and that the number is also being passed accurately to it.

If your page does not function correctly, check your code, ideally by reading it in a text editor with the ability to highlight PHP code. Try viewing the page source in your browser to see what HTML has actually been sent from the server side script.

Alter to Suit

This is the basic pattern for most PHP JavaScript function calls, but you will need to amend the script to suit the purpose of your own pages. As well as the HTML content, you will need to alter the PHP and JavaScript to address your own requirements, but the principle of calling a JavaScript function from PHP remains the same. Make sure you test your pages thoroughly before your website is exposed to users, as technologies such as JavaScript often behave differently across browsers.

Alternatives

As with most Web technologies, there are many different possible ways to combine JavaScript and PHP. The use of single and double quotation marks is just one option for handling JavaScript function calls from PHP. An alternative is to use escape characters, which indicate that a character is not being used in the normal way. For example, instead of the single inverted commas you can use all double and insert an escape character before those you want to appear in HTML:

echo "<input type=\"button\" value=\"button ".$count."\"
onclick=\"yourFunction(".$count.")\" />";

This is the method preferred by many developers, but as you can see the code can quickly become difficult to read. Which option you go for is entirely up to you, but personally, when escape characters are used excessively I tend to lose track of where I am and be more inclined to make syntax errors. As with everything in programming, it's best to stick with whatever approach makes the most sense to you.

Being able to read your code is always important, particularly where different languages are being used, as in this case, where it's vital to be able to see JavaScript in PHP code at a glance.

Notes
  • Create your Web pages incrementally, adding one element at a time and testing regularly. This makes mistakes easier to find and fix.
  • When you develop Web pages with both server side and client side languages, it's essential that you understand what happens on the server and what happens in the browser. If you're unsure about these things, it's well worth taking the time to familiarise yourself with the basics of the technologies involved.

See also:
How To: AJAX PHP Functions
How To Send Mail in PHP

Programming: Handling Code Errors

Encountering code errors is essentially a part of the daily reality of programming. The more programming you do, the more you begin to realise that the activity of coding is in large part about finding and fixing the mistakes you've made. You can forget about not making mistakes, unless you're a robot. Accepting the fact of code errors is actually a positive step in your development as a coder, as programming is primarily a problem solving task, which is ultimately why it's a rewarding one - honest!

Even if you could write an entire application without a single syntax error, you're always going to come up against errors or unforeseen problems with your code logic and implementation so it's vital to be able to handle them.

Approaches

Whether you're struggling with syntax errors (referred to as compile time errors if they prevent program compilation from occurring successfully), runtime errors, or logic errors preventing your programs doing what you need them to, there are a number of key helpful techniques.

These methods can help resolve code errors more quickly, and in some cases prevent them from arising in the first place. Effective error handling involves getting into good habits with your routine coding practises, as well as what you do when problems crop up, i.e. your debugging skills.

Planning

It may not be the sexiest part of programming, but taking the time to plan your development activities properly will inevitably reduce the amount of debugging you end up having to do. It's always tempting when you've just started working on an application or project to get stuck in start coding straight away, but it is genuinely the case that spending even a small amount of preparation time makes the development process less error prone and stressful.

Use a Code Highlighting Editor

For many developers this one goes without saying, but if you're perhaps just getting started as a coder, you might be amazed by how much easier it is to work with code that is highlighted. Depending on the language or technology you're working with, you may want to simply opt for a decent text editor that can highlight source code, such as Notepad++ on Windows or Gedit on Linux.

Use an IDE (Integrated Development Environment)

Depending on which language or platform you're working in, there may be one or more IDEs you can use for it. Integrated Development Environments come with a number of different tools, for example to help with debugging, visualising your applications and with the development process generally. At the very least, an IDE will highlight your code reliably, and in most cases will flag up any syntax errors so that you will typically catch them before you even attempt to compile and run your program.

Most IDEs also have some sort of error or output console which will indicate information about any runtime errors that occur. You can also use these output consoles for trace statements, as explained in the below section.

Use Comments and Documentation

It's something many programmers don't have the best habits for, but effective use of comments is one of the key defences against errors. Ideally, if you outline what the different elements in a program are going to do with comments before you even start writing code, as well as continuing as you write the code, this will provide a clear picture of what's going on throughout the development cycle.

Comments aren't just to help other people read and understand your code, as the more code you write the more you'll understand the regular nightmare of looking back at your own code and being totally baffled by it, sometimes only a short time after writing it in the first place.

Depending on the platform you're working in, and the size of application you're developing, you may want to consider documentation as part of your daily coding routine as well. For a language such as Java, the process of generating documentation is easily automated using tools such Javadoc, which again make the development process less frustrating.

Use Indentation and Whitespace

Effective use of indentation and whitespace in your source code files is another simple but often neglected practise that makes development much easier. Indenting your code makes the overall structures within it visible at a glance, particularly where structures such as conditionals, loops and class declarations are being used. If you're using an IDE, it may automate the process of correcting your indentation, particularly useful if it's in a bit of a mess.

Develop Incrementally

Sometimes you have to go against your instincts with programming to spare yourself some headaches down the line. If you've just started on a project or have just worked out how you want to approach part of it, it's tempting to get a load of code down quickly and without stopping. However, the more code you write in between testing, the more difficulty you'll have finding the syntax and logical errors within it.

Writing small amounts of code one at a time and testing regularly makes for programs that have fewer bugs, and in which the bugs are easier to locate and fix. If you're worried about remembering the details of an algorithm or solution to some problem you've been having, i.e. if you've just had a brainwave and want to get the code down before you forget the details, you can insert an overview as a note in a comment first, then set about implementing it in code.

Use Development Tools

Whether or not you're using an IDE, there will likely be development tools available for the language you're working with. If you're developing for the Web, there are a lot of browser tools that can help to find and fix errors. Tools such as Firebug can prove indispensable, particularly if you're working on large or complex applications.

If you're developing in an IDE, check out whatever debugging tools it has installed, or indeed whether there are any you can install as plugins. IDEs like Eclipse typically have a lot of optional extras you can install as well as the already extensive set of tools provided as standard.

Use Trace Statements

To fix code errors, you first have to locate them, and this can be the hardest part of the process. As well as developing in short bursts, testing each time you add some new aspect of functionality, you can give yourself some helpful clues as to what's going wrong using trace statements. A trace statement is generally something that you output to indicate what is happening at a specific point in your program.

Where your trace statements are output depends on the platform and IDE you're using, if appropriate. For IDEs there will typically be an output console, which you can write to directly, for example in this Java statement outputting the value of some variable at a particular point:

System.out.println("Data value: "+someVariable);

For Web development, you can output similar information from server side scripts to the browser, as in this PHP example:

echo "Data value: ".$someVariable."
";

In this case the value will simply appear within the webpage HTML, although this may not be ideal if you're working on a site that is already live - in these cases you can opt for something that will not be seen by site users, for example using server side tools such as writing to the PHP error log.

For client side scripting such as JavaScript, you can output information either to an alert dialog in the crudest example, which is again only suitable if you are working on a site that is not live:

alert("Data value: "+someVariable);

Alternatively, you can write your information to the log, which is also accessible using tools such as Firebug:

console.log("Data value: "+someVariable);

As well as using trace statements to check variable values as your code executes, you can use them to simply check whether the code is reaching a particular stage, for example to see if a function is definitely being called.

Isolate Error Prone Code Excerpts

If you're working on a large or complex project, it may help if you can separate any sections of code that are causing particular difficulties. This can help to locate the problem areas and can also make the testing process a little less cumbersome.

An alternative to copying chunks of source code into separate scripts, to be run independently, is to temporarily comment out those parts of code you do not need running to complete your debugging, letting you focus on the parts you're trying to troubleshoot.

Take Regular Breaks

It's yet another thing most of us know we should do but regularly fail to, but taking regular breaks can make the difference between success and failure when it comes to fixing code errors, as well as potentially stopping you going totally off your head! Sometimes I feel I've hit a complete dead end with a code problem, but after a short break I manage to find it relatively quickly and easily.

Links

Monday, 6 August 2012

Special Characters In Programming

Computer programming and markup code is naturally written with alphanumeric and other characters. However, within each language or technology, there are normally a set of characters that have a specific meaning or usage. This means that special consideration has to be given when those characters are used, for example when text strings are output for reading by users. The special characters for particular languages vary, as do techniques for handling them.

Coding

Whether a language is for programming or markup, there are typically always characters that cannot be used in the normal way. Those characters that have a specific meaning separate to their mainstream typographic use are generally considered special characters.

For example, within HTML, the tags surrounding Web page content use the "less than" and "greater than" characters:

<p>

This means that if those characters are to be used within an HTML page, they need to be included using their ASCII or ISO codes. For "less than" there are two options:

&#60; &lt;

Problems

When coding is carried out without sufficient handling of special characters, a number of problems may arise. For programming languages, code may not compile, and if it does there may be runtime errors.

For Web coding such as HTML markup, pages may not be rendered correctly, and their appearance may differ across Web browsers. Tools used to validate HTML and other Web markup to check whether it is well-formed will also show errors if special characters are not included properly.

Types

The types of special character depend on the language being used. In general, punctuation and non-alphanumeric characters may need special handling. There may also be characters that have a specified meaning within a particular language. For example, in many languages it is common to include text strings within quotation marks, for example in PHP:

$text="Here is some text";

If the text string also contains a quotation mark, this may cause a problem, as the compiling program will interpret the second quotation character it encounters as the end of the text string, preventing it from being able to process the code that follows.

Coping

The main technique for coping with special characters is to use an "escape" function. This is a shorthand syntax method letting the compiler know that a character is not being treated as it would be normally. For example, to include quotation marks in the PHP string:

$text="Here is \"some\" text";

The backslash is a common escape character used in many languages. The escape character is typically included immediately prior to the special character, preventing the compilation process from going wrong when it encounters the character in question.

Links

Special Characters | Webmonkey
Common HTML Validation Problems
Characters (The Java Tutorials > Learning the Java Language > Numbers and Strings)
PHP: htmlspecialchars - Manual
Special Characters - Microsoft

Monday, 23 July 2012

Web Development Concepts: Static Versus Dynamic

What is the difference between a static and dynamic Web page?

Essentially, whether a Web page is static or dynamic depends on what happens between the user making a request to see it, and the server sending the requested content to their browser. It makes no difference to users whether a page is static or dynamic, but is relevant to developers, as each model uses different techniques and technologies.

Essentially a static page is one whose content is stored in static, unchanging form in a document on the Web server, while the content of a dynamic page is only created when it is requested for viewing.

What happens when someone browses to a page?

When you browse to a Web page, for example by clicking a link or typing its URL into your browser address bar, your computer sends a request message to the Web server on which the requested page is hosted.

With a static page, the content is simply sitting in a file, typically in HTML, and the content of this file is returned by the server to your computer, where it is displayed in your browser window. For example, if you had a file saved as "page.html" on your server in the root directory, and browsed to it as follows:

http://exampledomain.com/page.html

The server would respond by sending the content of the file.

For dynamic pages, the process is different. Dynamic pages use programming languages such as PHP. In this case you would save your script on the server, for example using the name "page.php", and it would contain programming code as well as HTML code.

When the page is browsed to this time:

http://exampledomain.com/page.php

The code within the script file is executed (run) on the server. The server side program may do many different things, but typically one of them will be to build a Web page with HTML content and send this to the user's browser. The browser displays this HTML the same way it would have if the page had been static - the difference lies in what happens on the server, and makes no difference at the user (or "client") end.

How exactly is this different?

Static and dynamic pages don't just use different file formats, they use a fundamentally different technique. Static pages typically contain only markup code, whereas dynamic pages also contain programming code.

The content of an HTML file is basically text, images etc contained within a tree structure, with each element delineated by tags, each pair of opening and closing tags comprising an element as in the following example paragraph:

Some text...


This is HTML markup, and its structure, together with formatting such as CSS, tells the browser how the content of each element should be laid out and displayed.

With a dynamic page containing server side code, a different process takes place. The page script is executed according to its own logical structure, and as it goes it builds HTML structures and writes them out. This example PHP performs a simple calculation and writes the result out in HTML:

<?php
$answer=3*2;
echo "<p>".$answer."<p>";
?>

A typical PHP script will also do other things such as connecting to a database and querying it for data to write out as part of the HTML.

What are the advantages to using dynamic pages?

There are many advantages to using dynamic pages, the main one being the fact that they contain dynamic data. By connecting to a database, a dynamic page can potentially offer different content each time it is viewed. Static page content remains the same unless the page files themselves are manually changed, whereas dynamic pages populate their content at the time of viewing, according to what happens to be in the data store at that particular time.

It is often the case that many pages within a site will contain the same, or similar content. If this content needs to be changed, in a static site each page on which it occurs will need to be changed in turn. However, using dynamic scripting, the piece of content can be contained in a single, dedicated script, and this script can then be called from each page on which the content item appears. If the content needs to be changed, it only has to be changed in one place, i.e. the dedicated script, or the database if this is where it comes from.

Dynamic sites are therefore easier to maintain and to make changes to, while still keeping a consistent appearance and behaviour. If a site is being built for commercial purposes, being able to store the data in a database is also an advantage in itself.

Are there disadvantages to using dynamic pages?

The only potential disadvantage to using dynamic pages is the fact that a greater range of technologies, and therefore skills, are involved. A certain amount of programming expertise is necessary, and in most cases database development as well. However, if you're thinking about trying dynamic Web page development, don't be put off even if you have no programming experience, as these skills are actually relatively easy to pick up. There are lots of online tutorials and guides, so you really can teach yourself.

Do I need to use dynamic pages?


No! Using dynamic pages is not obligatory. However, depending on the purpose and nature of your site, it may be a real advantage. Setting your dynamic site up may seem an intimidating prospect, but once this is done the site will become much easier to amend and maintain. If your site only contains a small amount of simple information that does not need to be updated very often, there's probably no need to learn Web programming if it isn't something you're interested in.

How do I get started creating dynamic pages?

The first thing is to make sure you have a sound enough grasp of the basic Web technologies that are used in both static and dynamic pages, including the initial skills for making a Web page using HTML, CSS and JavaScript. You don't need to be at an advanced level, just make sure you understand the basic principles and practices.

Next is learning a server side language. I would recommend PHP, which is available on most Web hosting platforms. Start with the basics and build your knowledge incrementally, this is the only way to do it, and don't worry if you feel you're making slow progress, it will all fall into place eventually!

If you're building a dynamic site, you'll probably want to use a database. MySQL is available for free on many Web hosting packages and is a good system to start with. You can learn SQL if you like, but if your host provides phpMyAdmin, you can carry out most common tasks using the browser interface. If you're unsure about how to structure your database, it may be worth finding out a bit about relational database modelling.

Related Links
MySQL :: Developer Zone
MySQL Tutorial - Introduction
phpMyAdmin
PhpMyAdmin Tutorial
PHP: PHP Manual - Manual
PHP Tutorial
SQL Tutorial

Tech Interpreter Links:
Why Web Developers are Excited About HTML5 and CSS3
Using Scripts in HTML Pages
What is Web Content?
What is Dynamic Content?
Web Development Concepts: Client and Server
How to Get Started with Web Development