Discover millions of ebooks, audiobooks, and so much more with a free trial

From $11.99/month after trial. Cancel anytime.

Web Coding & Development All-in-One For Dummies
Web Coding & Development All-in-One For Dummies
Web Coding & Development All-in-One For Dummies
Ebook1,420 pages11 hours

Web Coding & Development All-in-One For Dummies

Rating: 1 out of 5 stars

1/5

()

Read preview
  • Web Development

  • Css

  • Php

  • Javascript

  • Html

  • Mysql

  • Fetch Api

  • Command Line Program

  • Web Coding

  • Web Forms

About this ebook

Learn the in-demand skills that let you turn lines of code into websites and apps

Web Coding & Development All-in-One For Dummies is a one-stop resource for would-be developers who need guidance on the languages and steps used to build websites and applications. Learn the coding ropes and expand your existing skillset with this easy-to-understand guide. In these complete mini-books, you’ll walk through the basics of web development, structuring a page, building and processing web forms, and beyond. Learn how to build a website or create your very own app with the advice of web coding and development experts. This edition expands JavaScript and CSS coverage while providing new content on server-side coding and the development stack.

  • Get essential knowledge of how web development works—even if you’ve never written a line of code in your life
  • Learn HTML, CSS, JavaScript, and other languages essential for building websites and apps
  • Discover how to make optimize your sites and apps for mobile devices
  • Expand on what you already know and improve your employability

This Dummies All-in-One is great for you if want to develop coding skills but don’t have a programming background. It’s also perfect for professionals looking to brush up on their web development skills and get up to date on the latest trends and standards.

LanguageEnglish
PublisherWiley
Release dateDec 29, 2023
ISBN9781394197033
Web Coding & Development All-in-One For Dummies
Author

Paul McFedries

Paul McFedries has written nearly 100 books, which have sold over four million copies world-wide

Read more from Paul Mc Fedries

Related to Web Coding & Development All-in-One For Dummies

Related ebooks

Internet & Web For You

View More

Related articles

Reviews for Web Coding & Development All-in-One For Dummies

Rating: 1 out of 5 stars
1/5

1 rating0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Web Coding & Development All-in-One For Dummies - Paul McFedries

    Introduction

    When the web first came to the attention of the world’s non-geeks back in the mid-1990s, the vastness and variety of its treasures were a wonder to behold. However, it didn’t take long before a few courageous and intrepid souls dug a little deeper into this phenomenon and discovered something truly phenomenal: They could make web pages, too!

    Why was that so amazing? Well, think back to (or, if you’re not old enough, imagine) those old days and consider, in particular, what it meant to create what we now call content. Consider television shows, radio programs, magazines, newspapers, books, and the other media of the time. The one thing they all had in common was that their creation was a decidedly uncommon thing. It required a team of professionals, a massive distribution system, and a lot of money. In short, it wasn’t something that your average Okie from Muskogee would have any hope of duplicating.

    The web appeared to change all that because learning HTML was within the grasp of all of us who could feed ourselves, it had a built-in massive distribution system (the internet, natch), and it required little or no money. For the first time in history, content was democratized and was no longer defined as the sole province of governments and mega-corporations.

    Then reality set in.

    People soon realized that merely building a website wasn’t enough to attract eyeballs, as the marketers say. A site had to have interesting, useful, or fun content, or people would stay away in droves. Not only that, but this good content had to be combined with a solid site design, which meant that web designers needed a thorough knowledge of HTML and CSS.

    But, alas, eventually even all that was not enough. To make their websites dynamic and interesting, to make their sites easy to navigate, and to give their sites those extra bells and whistles that surfers had come to expect, people needed something more than content, HTML, and CSS.

    That missing link was code.

    What we’ve all learned the hard way over the past few years is that you simply can’t put together a world-class website unless you have some coding prowess in your site design toolkit. You need to know how to program your way out of the basic problems that afflict most sites; how to use scripting to go beyond the inherent limitations of HTML and CSS; and how to use code to send and receive data from a web server. And it isn’t enough just to copy the generic scripts available on the web and paste them into your pages. Most of those scripts are poorly written, and they invariably need some customization to work properly on your site.

    About This Book

    In this book, I give you a complete education on web coding and development. You learn how to set up the tools you need, how to use HTML and CSS to design and build your site, how to use JavaScript to program your pages, and how to use PHP and MySQL to program your web server. I show you that these technologies aren’t hard to learn, and that even the greenest rookie programmers can learn how to put together web pages that will amaze their family and friends (and themselves).

    If you’re looking for lots of programming history, computer science theory, and long-winded explanations of concepts, you won’t find them here. My philosophy throughout this book comes from Linus Torvalds, the creator of the Linux operating system: Talk is cheap. Show me the code. I explain what needs to be explained and then I move on without further ado (or, most of the time, without any ado at all) to examples and scripts that do more to illuminate a concept that any verbose explanations I could muster (and believe me, I can muster verbosity with the best of them).

    How you approach this book depends on your current level of web coding expertise (or lack thereof):

    If you’re just starting out, begin at the beginning with Book 1 and work at your own pace sequentially through to Books 2 and 3. This approach will give you all the knowledge you need to pick and choose what you want to learn throughout the rest of the book.

    If you know HTML and CSS, you can probably get away with taking a fast look at Book 2 and then settling in with Book 3 and beyond.

    If you’ve done some JavaScript coding, I suggest working quickly through the material in Book 3, and then digging into the first two chapters of Book 5 to bring your debugging skills up to snuff. You’ll then be ready to branch out and explore the rest of the book as you see fit.

    If you’re a relatively experienced JavaScript programmer, use Books 3 and 5 as a refresher, and then tackle Book 4 to learn how to code the back end. I have a few tricks in there that you might find interesting. After that, feel free to consider the rest of the book as a kind of coding smorgasbord that you can sample as your web development taste buds dictate.

    As I began updating this edition of the book, the world was awash in posts and talk and endless speculation about artificial intelligence, to the point where it seemed we’d soon be welcoming our new AI overlords. That’s not likely to happen anytime soon, but AI is here to stay and has already established itself as a significant part of many people’s workaday routines.

    I’ve been as enamored of ChatGPT and its ilk as the biggest AI boosters. I use AI for entertainment and curiosity, but I don’t use it for work. That is to say, not one word of the text, code, or examples used in this book has been generated by AI. Everything you read here is, for good or ill, the product of my warped-from-birth brain.

    Foolish Assumptions

    This book is not a primer on the internet or using the World Wide Web. It's a coding and development book, pure and simple, where I assume the following:

    You know how to operate a basic text editor and how to get around the operating system and file system on your computer.

    You have an internet connection.

    You know how to use your web browser.

    Yep, that’s it.

    If you’ve never done a stitch of computer programming before, even if you’re not quite sure what programming really is, don’t worry about it for a second because I had you in mind when I wrote this book. For too many years, programming has been the property of hackers and other technowizards. That made some sense because the programming languages they were using — with bizarre names such as C++ and Perl — were exceedingly difficult to learn and even harder to master.

    This book’s main coding technologies — HTML, CSS, JavaScript, PHP, and MySQL — are different. They’re nowhere near as hard to learn as those for-nerds-only languages. I honestly believe that anyone can become a savvy and successful web coder, and this book is, I hope, the proof of that assertion. If you just follow along, examine my code carefully (particularly in the first few chapters), and practice what you learn, you will master web coding and development.

    What if you’ve done some programming in the past? For example, you might have dipped a toe or two in the JavaScript waters already, or you might have dabbled with HTML and CSS. Will this book be too basic for you? No, not at all. In this book, I provide you with a ton of truly useful examples that you can customize and incorporate into your own site. The book’s first few chapters start slowly to avoid scaring off those new to this programming business. But once you get past the basics, I introduce you to lots of great techniques and tricks that will take your web coding skills to a higher level.

    Icons Used in This Book

    Remember This icon points out juicy tidbits that are likely to be repeatedly useful to you — so please don’t forget them.

    Tip Think of these icons as the fodder of advice columns. They offer (I hope) wise advice or a bit more information about a topic under discussion.

    Warning Look out! In this book, you see this icon when I’m trying to help you avoid mistakes that can cost you time, money, or embarrassment.

    Technical Stuff When you see this icon, you’ve come across material that isn’t critical to understand but will satisfy the curious. Think inquiring minds want to know when you see this icon.

    Beyond the Book

    Some extra content for this book is available on the web. Go online to find the following:

    The examples used in the book: You can find these on my website:

    https://paulmcfedries.com/books/web-coding-dev-aio-fd-2e/

    Alternatively, the examples are also available via the book’s GitHub repository:

    https://github.com/paulmcfe/web-coding-and-dev-fd-2e

    The examples are organized by book and then by chapter within each book. For each example, you can view the code, copy it to your computer’s clipboard, and run the code in the browser.

    The WebDev Workshop: To view a few web coding tools and tutorials, as well as try your own code and see instant results, fire up the following site:

    https://webdevworkshop.io

    You won’t break anything, so feel free to use the site to run some experiments and play around with HTML, CSS, and JavaScript.

    Book 1

    Getting Ready to Code for the Web

    Contents at a Glance

    Chapter 1: How Web Coding and Development Work

    The Nuts and Bolts of Web Coding and Development

    Understanding the Front End: HTML and CSS

    Understanding the Back End: PHP and MySQL

    How It All Fits Together: JavaScript

    How Dynamic Web Pages Work

    What Is a Web App?

    Understanding the Difference between Web Coding and Web Development

    Chapter 2: Setting Up Your Web Development Home

    What Is a Local Web Development Environment?

    Do You Need a Local Web Development Environment?

    Setting Up the XAMPP for Windows Development Environment

    Setting Up the XAMPP for OS X Development Environment

    Choosing Your Text Editor

    Chapter 3: Finding and Setting Up a Web Host

    Understanding Web Hosting Providers

    A Buyer’s Guide to Web Hosting

    Finding a Web Host

    Finding Your Way around Your New Web Home

    Chapter 1

    How Web Coding and Development Work

    IN THIS CHAPTER

    Bullet Learning how the web works

    Bullet Understanding the front-end technologies of HTML and CSS

    Bullet Understanding the back-end technologies of MySQL and PHP

    Bullet Figuring out how JavaScript fits into all of this

    Bullet Learning about dynamic web pages, web apps, and mobile web apps

    More than mere consumers of technology, we are makers, adapting technology to our needs and integrating it into our lives.

    — DALE DOUGHERTY

    The 1950s were a hobbyist’s paradise with magazines such as Mechanix Illustrated and Popular Science showing the do-it-yourselfer how to build a go-kart for the kids and how to soup up a lawnmower with an actual motor! Seventy years later, we’re now firmly entrenched in the age of do-it-yourself tech, where folks indulge their inner geek to engage in various forms of digital tinkering and hacking. The personification of this high-tech hobbyist renaissance is the maker, a modern artisan who lives to create things rather than merely consume them. Today’s makers exhibit a wide range of talents, but the skill most sought-after not only by would-be makers themselves but by the people who hire them is web coding and development.

    Have you ever visited a website and thought, Hey, I can do better than that!? Have you found yourself growing tired of merely reading text and viewing images that someone else has put on the web? Is there something creative in you — stories, images, expertise, opinions — that you want to share with the world? If you answered a resounding Yes! to any of these questions, congratulations: You have everything you need to get started with web coding and development. You have, in short, the makings of a maker.

    The Nuts and Bolts of Web Coding and Development

    If, as the King said very gravely in Lewis Carroll’s Alice in Wonderland, it’s best to begin at the beginning, you’ve come to the right place. My goal here is to get you off on the right foot by showing you what web coding and web development are.

    How the web works

    Before you can understand web coding and development, you need to take a step back and understand a bit about how the web itself works. In particular, you need to know what happens behind the scenes when you click a link or type a web page address into your browser. Fortunately, you don’t need to be a network engineer to understand this stuff, because I can explain the basics without much in the way of jargon. Here’s a high-level (and not at all serious) blow-by-blow account of what happens:

    You tell the web browser the web page you want to visit.

    You do that either by clicking a link to the page or by typing the location — known as the uniform resource locator or URL (usually pronounced you-are-ell, but also sometimes earl) — into the browser’s address bar (see Figure 1-1).

    A screenshot of a Google browser's address bar page with U R L.

    FIGURE 1-1: One way to get to a web page is to type the URL in the browser’s address bar.

    The browser decodes the URL.

    Decoding the URL means two things. First, the browser sees what type of resource you’re requesting by checking the prefix of the URL; this is usually http:// or https://, both of which indicate that the resource is a web page. Second, it gets the URL's domain name — the something.com or whatever.org part — and asks the domain name system (DNS) to translate this into a unique location — called the IP (Internet Protocol) address — for the web server that hosts the page (see Figure 1-2).

    A screenshot of the output page with decoding U R L. The results include prefix, domain name, and web server I P address.

    FIGURE 1-2: The browser extracts the prefix, domain, and the server address from the URL.

    The browser contacts the web server and requests the web page.

    With the web server's unique IP address in hand, the web browser sets up a communications channel with the server and then uses that channel to send along a request for the web page (see Figure 1-3).

    A screenshot of the U R L 172.64.80.1 displays a text with the web browser sets up a communications channel with the server and a request for the web page.

    FIGURE 1-3: The browser asks the web server for the web page.

    The web server decodes the page request.

    Decoding the page request involves a number of steps. First, if the web server is shared between multiple user accounts, the server begins by locating the user account that owns the requested page. The server then uses the page address to find the directory that holds the page and the file in which the page code is stored (see Figure 1-4).

    A screenshot of the output page with decoding U R L. The results include user account, directory, and filename.

    FIGURE 1-4: The server uses the page request to get the account, directory, and filename.

    The web server sends the web page file to the web browser (see Figure1-5).

    A screenshot of a webpage displays the response message for browser requests.

    FIGURE 1-5: The web server sends the requested web page file to the browser.

    The web browser decodes the web page file.

    Decoding the page file means looking for text to display, instructions on how to display that text, and other resources required by the page, such as images and fonts (see Figure 1-6).

    A screenshot of the output page with decoding U R L. The results include text, formatting, images, audio, video, and data.

    FIGURE 1-6: The web browser scours the page file to see if it needs anything else from the server.

    If the web page requires more resources, the web browser asks the server to pass along those resources (see Figure1-7).

    For each of the requested resources, the web server locates the associated file and sends it to the browser (see Figure1-8).

    The web browser gathers all the text, images, and other resources and displays the page in all its digital splendor in the browser’s content window (see Figure1-9).

    A screenshot of a webpage displays the response message from the browser and requesting further information to a server.

    FIGURE 1-7: The web browser goes back to the server to ask for the other data needed to display the web page.

    A screenshot of a webpage displays the server response to the browser request.

    FIGURE 1-8: The web server sends the browser the rest of the requested files.

    A web browser screenshot displays the Webdev Workshop page with programming examples.

    FIGURE 1-9: At long last, the web browser displays the web page.

    How the web works, take two

    Another way to look at this process is to think of the web as a giant mall or shopping center, where each website is a storefront in that mall. When you request a web page from a particular site, the browser takes you into that site’s store and asks the clerk for the web page. The clerk goes into the back of the store, locates the page, and hands it to the browser. The browser checks the page and asks for any other needed files, which the clerk retrieves from the back. This process is repeated until the browser has everything it needs, and it then puts all the page pieces together for you, right there in the front of the store.

    This metaphor might seem a bit silly, but it serves to introduce yet another metaphor, which itself illustrates one of the most important concepts in web development. In the same way that our website store has a front and a back, so, too, is web development separated into a front end and a back end:

    Front end: That part of the web page that the web browser displays in the browser window. That is, the front end is the page stuff you see and interact with.

    Back end: That part of the web page that resides on the web server. That is, the back end is the page stuff that the server gathers based on the requests it receives from the browser.

    As a consumer of web pages, you only ever deal with the front end, and even then you only passively engage with the page by reading its content, looking at its images, or clicking its links or buttons.

    However, as a maker of web pages — that is, as a web developer — your job entails dealing with both the front end and the back end. Moreover, that job includes coding what others see on the front end, coding how the server gathers its data on the back end, and coding the intermediate tasks that tie the two together.

    Understanding the Front End: HTML and CSS

    As I mention in the preceding section, the front end of the web development process involves what users see and interact with in the web browser window. It’s the job of the web developer to take a page design — which you might come up with yourself but is more often something cooked up by a creative type who specializes in web design — and make it web-ready. Getting a design ready for the web means translating the design into the code required for the browser to display the page somewhat faithfully. (I added the hedge word somewhat there because it’s not always easy to take a design that looks great in Photoshop or Illustrator and make it look just as good on the web. However, with the techniques you learn in this book, you’ll almost always be able to come pretty close.)

    You need code to create the front end of a web page because without it your page will be quite dull. For example, consider the following text (found in bk01ch01/example01.html in this book’s example files):

    There once was a boy named Flibbertigibbet. No, his parents most certainly did not give him that name when he was born. That would have been cruel, and they were really quite nice people. They actually named him Filbert. Yes, they named him after a nut. They were nice people, but they were also silly people who often didn't think things through.

    One day, when Filbert was about a year old, his mother was bouncing him on her knee when, mid-dandle, he smiled and said Momma! Oh, his mother was overjoyed that not only had Filbert said his first word but that word had been Momma. She called her husband over and Filbert looked right at him and said Dadda! Amazing! They began pointing at him and repeating Filbert!, Filbert! to get him to say his own name. After a while, Filbert creased his brow as though concentrating ever so seriously, and then said Flibbertigibbet!

    Their jaws dropped. How could a boy so young know such a word? Ah, therein lies a tale. Unbeknownst to his parents, Filbert's maternal grandmother had been secretly whispering You're my little Flibbertigibbet in her grandson's ear over and over since the day he was born. By the time he was a year old, the boy didn't know many things, but there was one thing he knew with unshakeable conviction: His name was Flibbertigibbet!

    If you plop that text onto the web, you get the result shown in Figure 1-10. As you can see, the text is very plain, and the browser didn’t even bother to include the paragraph breaks.

    A web browser screenshot displays the dishwater-dull website in one paragraph.

    FIGURE 1-10: Text-only web pages are dishwater-dull.

    So, if you can’t just throw naked text onto the web, what’s a would-be web developer to do? Ah, that’s where you start earning your web scout merit badges by adding code that tells the browser how you want the text displayed. That code comes in two flavors: structure and formatting.

    Adding structure: HTML

    The first thing you usually do to code a web page is give it some structure. This means breaking up the text into paragraphs, adding special sections such as a header and footer, organizing text into bulleted or numbered lists, dividing the page into columns, and much more. The web coding technology that governs these and other web page structures is called (deep breath) Hypertext Markup Language, or HTML, for short.

    HTML is a collection of special symbols called tags that you sprinkle strategically throughout the page. For example, if you want to tell the web browser that a particular chunk of text is a separate paragraph, you place the

    tag (the p here is short for paragraph) before the text and the

    tag after the text.

    In the code that follows (check out bk01ch01/example02.html), I've added these paragraph tags to the plain text that I show earlier. As shown in Figure 1-11, the web browser displays the text as three separate paragraphs, no questions asked.

    There once was a boy named Flibbertigibbet. No, his parents most certainly did not give him that name when he was born. That would have been cruel, and they were really quite nice people. They actually named him Filbert. Yes, they named him after a nut. They were nice people, but they were also silly people who often didn't think things through.

           

    One day, when Filbert was about a year old, his mother was bouncing him on her knee when, mid-dandle, he smiled and said Momma! Oh, his mother was overjoyed that not only had Filbert said his first word but that word had been Momma. She called her husband over and Filbert looked right at him and said Dadda! Amazing! They began pointing at him and repeating Filbert!, Filbert! to get him to say his own name. After a while, Filbert creased his brow as though concentrating ever so seriously, and then said Flibbertigibbet!

    Their jaws dropped. How could a boy so young know such a word? Ah, therein lies a tale. Unbeknownst to his parents, Filbert's maternal grandmother had been secretly whispering You're my little Flibbertigibbet in her grandson's ear over and over since the day he was born. By the time he was a year old, the boy didn't know many things, but there was one thing he knew with unshakeable conviction: His name was Flibbertigibbet!

    A book page with three paragraphs is displayed in a web browser screenshot.

    FIGURE 1-11: Adding paragraph tags to the text separates the text into three paragraphs.

    Remember HTML is one of the fundamental topics of web development, and you learn all about it in Book 2, Chapter 1.

    Adding style: CSS

    HTML takes care of the structure of the page, but if you want to change the formatting of the page, you need to turn to a second front-end technology: cascading style sheets, known almost universally as just CSS. With CSS in hand, you can play around with the page colors and fonts, you can add margins and borders around things, and you can mess with the position and size of page elements.

    CSS consists of a large number of properties that enable you to customize many aspects of the page to make it look the way you want. For example, the width property lets you specify how wide a page element should be; the font-family property enables you to specify a typeface for an element; and the font-size property lets you dictate the type size of an element’s text. Here's some CSS code that applies all three of these properties to every p element (that is, every

    tag) that appears in a page (note that px is short for pixels):

    p {

        width: 700px;

        font-family: sans-serif;

        font-size: 24px;

    }

    When used with the sample text from the previous two sections, you get the much nicer-looking text shown in Figure 1-12. (Also check out bk01ch01/example03.html.)

    A book page with three paragraphs is displayed in a web browser screenshot with a use of C S S properties.

    FIGURE 1-12: With the judicious use of a few CSS properties, you can greatly improve the look of a page.

    Remember CSS is a cornerstone of web development. You learn much more about it in Book 2, Chapters 2, 3, and 4.

    Remember You learn quite a bit of CSS in this book, but if you really want to dive deep into this crucial web development technology, see my book HTML, CSS & JavaScript All-in-One For Dummies (2023).

    Understanding the Back End: PHP and MySQL

    Many web pages are all about the front end. That is, they consist of nothing but text that has been structured by HTML tags and styled by CSS properties, plus a few extra files such as images and fonts. Sure, all these files are transferred from the web server to the browser, but that’s the extent of the back end’s involvement.

    These simple pages are ideal when you have content that doesn’t change very often, if ever. With these so-called static pages, you plop in your text, add some HTML and CSS, perhaps point to an image or two, and you’re done. Static pages are awesome, by the way, which is why I talk about them in some detail in Book 6.

    But another class of page has content that changes frequently. The content could be posts added once or twice a day, or sports or weather updates added once or twice an hour. With these so-called dynamic pages, you might have some text, HTML, CSS, and other content that’s static, but you almost certainly don’t want to be updating the changing content by hand.

    Rather than making constant manual changes to such pages, you can convince the back end to do it for you. You do that by taking advantage of two popular back-end technologies: MySQL and PHP.

    Storing data on the server: MySQL

    MySQL is a relational database management system that runs on the server. You use it to store the data you want to use as the source for some (or perhaps even all) of the data you want to display on your web page. Using a tool called Structured Query Language (SQL, pronounced ess-kew-ell, or sometimes sequel), you can specify which subset of your data you want to use.

    Remember If phrases such as relational database management system and Structured Query Language have you furrowing your brow, don’t sweat it: I explain all in Book 4, Chapter 2.

    Accessing data on the server: PHP

    PHP is a programming language used on the server. It’s a very powerful and full-featured language, but for the purposes of this book, you use PHP mostly to interact with MySQL databases. You can use PHP to extract from MySQL the subset of data you want to display, manipulate that data into a form that’s readable by the front end, and then send the data to the browser.

    Remember You learn about the PHP language in Book 4, Chapter 1, and you learn how to use PHP to access MySQL data in Book 4, Chapter 3.

    How It All Fits Together: JavaScript

    Okay, so now you have a front end consisting of HTML structure and CSS styling, and a back end consisting of MySQL data and PHP code. How do these two seemingly disparate worlds meet to create a full web page experience?

    In the website-as-store metaphor that I introduce earlier in this chapter, I use the image of a store clerk taking an order from the web browser and then going into the back of the store to fulfill that order. That clerk is the obvious link between the front end and the back end, so what technology does that clerk represent? That would be JavaScript.

    JavaScript is the secret sauce that brings the front end and the back end together to create the vast majority of the web pages you see today. JavaScript is a programming language and is the default language used for coding websites today. JavaScript is, first and foremost, a front-end web development language. That is, JavaScript runs inside the web browser and has access to everything on the page: the text, the images, the HTML tags, the CSS properties, and more. Having access to all the page stuff means that you can use code to manipulate, modify, and even add and delete web page elements.

    But although JavaScript runs in the browser, it’s also capable of reaching out to the server to access back-end stuff. For example, with JavaScript you can send data to the server to store that data in a MySQL database. Similarly, with JavaScript you can request data from the server and then use code to display that data on the web page.

    Remember JavaScript is very powerful, very useful, and very cool, so Book 3 takes 11 full chapters to help you learn it well. Also, you learn how JavaScript acts as a bridge between the front end and the back end in Book 6, Chapter 1.

    How Dynamic Web Pages Work

    It’s one thing to know about HTML and CSS and PHP and all the rest, but it’s quite another to actually do something useful with these technologies. That, really, is the goal of this book, and to that end the book spends several chapters covering how to create wonderful things called dynamic web pages. A dynamic web page is one that includes content that, rather than being hard-wired into the page, is generated on-the-fly from the web server. This means the page content can change based on a request by the user, by data being added to or modified on the server, or in response to some event, such as the clicking of a button or link.

    It likely sounds a bit like voodoo to you now, so perhaps a bit more detail is in order. For example, suppose you want to use a web page to display some data that resides on the server. Here’s a general look at the steps involved in that process:

    JavaScript determines the data that it needs from the server.

    JavaScript has various ways it can do this, such as extracting the information from the URL, reading an item the user has selected from a list, or responding to a click from the user.

    JavaScript sends a request for that data to the server.

    In most cases, and certainly in every case you see in this book, JavaScript sends this request by calling a PHP script on the server.

    The PHP script receives the request and passes it along to MySQL.

    The PHP script uses the information obtained from JavaScript to create an SQL command that MySQL can understand.

    MySQL uses the SQL command to extract the required information from the database and then return that data to the PHP script.

    The PHP script manipulates the returned MySQL data into a form that JavaScript can use.

    JavaScript can’t read raw MySQL data, so one of PHP’s most important tasks is to convert that data into a format called JavaScript Object Notation (JSON, for short, and pronounced like the name Jason), which JavaScript is on friendly terms with (see Book 6, Chapter 1 for more about this process).

    PHP sends the JSON data back to JavaScript.

    JavaScript displays the data on the web page.

    One of the joys of JavaScript is that you get tremendous control over how you display the data to the user. Through existing HTML and CSS, and by manipulating these and other web page elements using JavaScript, you can show your data in the best possible light.

    Remember To expand on these steps and learn how to create your own dynamic web pages, check out the first three chapters in Book 6.

    What Is a Web App?

    You no doubt have a bunch of apps residing on your smartphone. If you use Windows on your PC, you have the pre-installed apps such as Mail and Calendar and possibly one or more apps downloaded from the Windows Store. If the Mac is more your style, you’re probably quite familiar with apps such as Music and Messages, and you might have installed a few others from the App Store. We live in a world full of apps that, in the context of your phone or computer, are software programs dedicated to a single topic or task.

    So what then is a web app? It’s very similar to an app on a device or PC. That is, it’s a website, built using web technologies such as HTML, CSS, and JavaScript, that has two main characteristics:

    The web app is focused on a single topic or task.

    The web app offers some sort of interface that enables the user to operate the app in one or more ways.

    In short, a web app is a website that looks and acts like an app on a device or a computer. (Gmail is an example of a web app.) This is opposed to a regular website, which usually tackles several topics or tasks and has an interface that for the most part only enables users to navigate the site.

    Remember To get the scoop on building your very own web apps, head over to the four chapters in Book 7.

    Understanding the Difference between Web Coding and Web Development

    After all this talk of HTML, CSS, MySQL, and JavaScript, after the bird’s-eye view of static sites, dynamic sites, and web apps, you might be wondering when the heck I’m going to answer the most pressing question: What in the name of Sir Tim Berners-Lee (inventor of the web) is the difference between web coding and web development?

    I’m glad you asked! Some people would probably answer that question by saying there’s no real difference because web coding and web development are two ways of referring to the same thing: creating web pages using programming tools.

    Hey, it’s a free country, but to my mind I think there’s a useful distinction to be made between web coding and web development:

    Web coding is the pure programming part of creating a web page, particularly using JavaScript on the front end and PHP on the back end.

    Web development is the complete web page creation package, from building a page with HTML tags, to formatting the page with CSS, to storing data on the back end with MySQL, to accessing that data with PHP, to bridging the front and back ends using JavaScript.

    However you look at the two terms, this book teaches you everything you need to know to become both a web coder and a web developer.

    Chapter 2

    Setting Up Your Web Development Home

    IN THIS CHAPTER

    Bullet Understanding the need for a web development environment

    Bullet Gathering the tools you need for a local development setup

    Bullet Installing a local web development environment on a Windows PC

    Bullet Installing a local web development environment on a Mac

    Bullet Learning what to look for in a good text editor

    He is happiest, be he king or peasant, who finds peace in his home.

    — JOHANN WOLFGANG VON GOETHE

    One of the truly amazing things about web development is that, with just a few exceptions — such as images, media files, and server databases — all you ever work with are basic text files. But surely all the structure you add with HTML tags requires some obscure and complex file type? No way, José: It’s text all the way down. What about all that formatting stuff associated with CSS? Nope: nothing but text. PHP and JavaScript? Text and, again, text.

    What this text-only landscape means is that you don’t need any highfalutin, high-priced software to develop for the web. A humble text editor is all you require to dip a toe or two in the web coding waters.

    But what if you want to get more than your feet wet in web coding? What if you want to dive in, swim around, perhaps do a little snorkeling? Ah, then you need to take things up a notch or three and set up a proper web development environment on your computer. Doing so will give you everything you need to build, test, and refine your web development projects. In this chapter, you get your web coding adventure off to a rousing start by exploring how to set up a complete web development environment on your Windows PC or Mac.

    What Is a Local Web Development Environment?

    In programming circles, an integrated development environment (IDE) is a collection of software programs that make it easy and efficient to write code. Most development environments are tailored to a particular programming language and come with tools for editing, testing, and compiling code (that is, converting the code to its final form as an application).

    In the web coding game, we don’t have IDEs, per se, but we do have a similar beast called a local web development environment, which is also a collection of software. It usually includes the following:

    A web server

    A relational database management system (RDBMS) to run on the web server

    A server-side programming language

    An interface for controlling (starting, stopping, and so on) the web server

    An interface for accessing and manipulating the RDBMS

    The key point to grok here is that this is a local web development environment, which means it gets installed on your PC or Mac. This enables you to build and test your web development projects right on your computer. You don’t need a web hosting service or even an internet connection. Everything runs conveniently on your computer, so you can concentrate on coding and leave the deployment of the site until you’re ready.

    Do You Need a Local Web Development Environment?

    Okay, if it’s possible to use a simple text editor to develop web pages, why not do just that? After all, every Windows PC and Mac in existence comes with a pre-installed text editor, and lots of free third-party text editors are ripe for downloading, so why bother installing the software for a local web development environment?

    To be perfectly honest, I’m not going to stand here and tell you that a local web development setup is a must. Certainly, if all you’re doing for now is getting started with a few static web pages built using HTML, CSS, and JavaScript, you don’t yet need access to the back end. Similarly, if you are building websites and web apps for your own use and already have a web host that gives you access to MySQL and PHP, you can definitely get away with using just your trusty text editor.

    However, two major exceptions pretty much require you to build your web stuff locally:

    You’re building a website or app for someone else and you don’t have access to their web server.

    You’re building a new version of an existing website or app, which means you don’t want to mess with the production code while tinkering (and therefore making mistakes) with the new code.

    That said, there’s also something undeniably cool about having a big-time web server purring away in your computer's background. So, even if you don’t think you’ll need a full-blown web development environment in the short term, think about installing one anyway, if only so you can say you’re running Apache 2.4 locally at your next cocktail party.

    Setting Up the XAMPP for Windows Development Environment

    If you’re running Windows, I highly recommend the web development environment XAMPP for Windows, which in its most recent version (at least as I write this in late-2023) requires Windows Vista or later. XAMPP for Windows is loaded with dozens of features, but for our needs the following are the most important:

    Apache: An open-source web server that runs about half of all the websites on Earth

    MariaDB: An open-source server database that is fully compatible with MySQL (discussed in Book 1, Chapter 1)

    PHP: The server-side programming language that I talk about briefly in Book 1, Chapter 1

    phpMyAdmin: An interface that enables you to access and manipulate MariaDB databases

    So, all this high-end software requires big bucks, right? Nope. XAMPP for Windows is free.

    To get started, head to the Apache Friends website at www.apachefriends.org and download XAMPP for Windows. Be sure to get the most recent version.

    Installing XAMPP for Windows

    Once the download is complete, follow these steps to install XAMPP for Windows:

    Open the Downloads folder and then launch the installation file that you downloaded.

    The download is an executable file, so you can double-click it to get the installation off the ground.

    Enter your User Account Control (UAC) credentials to allow the install.

    If you’re the administrator of your PC, click Yes. Otherwise, you need to enter the username and password of the PC’s administrator account.

    When XAMPP displays a warning about installing with UAC activated, click OK.

    This oddly worded warning means that if you install XAMPP in the default folder (usually C:\Program Files), it might have problems running normally because UAC imposes restrictions on that folder. You can ignore this because, in Step 6, I show you how to install XAMPP in a different folder that doesn't suffer from this problem.

    When the XAMPP Setup Wizard appears, click Next.

    In the Select Components dialog box, shown in Figure2-1, deselect the check box beside any component you don’t want installed, and then click Next.

    For a basic install, you only need Apache, MySQL, PHP, and phpMyAdmin. If your PC is running low on disk space, consider not installing the other components. If you’re rich in disk space, go ahead and install everything because, hey, after all of this you might be inspired to learn Perl (which is another server-side programming language).

    A screenshot of the setup wizard dialog box displays the check boxes in select components options.

    FIGURE 2-1: Use this Setup Wizard dialog box to deselect the check box beside any component you don’t want installed.

    In the Installation Folder dialog box, type the location where you want XAMPP installed, then click Next.

    Be sure to avoid the folders C:\Program Files and C:\Program Files (x86), for the reason I describe in Step 3. Most folks create a xampp folder in C:\ and install everything there (as shown in Figure 2-2).

    A screenshot of the setup wizard dialog box displays the installation folder page.

    FIGURE 2-2: To install XAMPP, use a subfolder in the main C:\ folder (such as C:\xampp).

    When the Setup Wizard asks what language you want to use, choose a language and then click Next.

    Click Next to begin the installation.

    If you encounter a Windows Security dialog box, click Show More. Select the Private Networks check box and deselect the Public Networks check box, as shown in Figure2-3, and then click Allow.

    Remember However, just because you select the Private Networks check box, it doesn’t mean that people on your network can access (much less mess with) your local web server. XAMPP for Windows is configured out of the box to be accessible only from the computer on which it’s installed.

    A screenshot of a Windows security dialog box. Private networks check box is selected from Apache H T T P server.

    FIGURE 2-3: If the Windows Security dialog box shows up, be sure to allow Apache to communicate on your private network but not on any public networks.

    When the install is complete, deselect the Do You Want to Start the Control Panel Now check box.

    I talk about the correct way to start the Control Panel in the next section.

    Click Finish.

    Running the XAMPP for Windows Control Panel

    The XAMPP Control Panel enables you to start, stop, and configure the XAMPP apps, particularly the Apache web server and the MySQL database system. For best results, you should start the program with administrator privileges, which you can do by following these steps:

    Click Start.

    In the All Apps list, find and open the XAMPP folder.

    Depending on your version of Windows, you might have to click All Apps to get to the All Apps list.

    Right-click XAMPP Control Panel, click More, and then click Run as Administrator.

    Depending on your version of Windows, you might not have to click More to get to the Run as Administrator command.

    The User Account Control dialog appears.

    If you’re the administrator of your PC, click Yes. Otherwise, you need to enter the username and password of the PC’s administrator account.

    The XAMPP Control Panel appears, as shown in Figure 2-4.

    The screenshot of the X A M P P control panel page. It serves the options of module services, PID, ports, and action of configurations.

    FIGURE 2-4: You use the XAMPP Control Panel to control and configure apps such as Apache and MySQL.

    To start an app, click the corresponding Start button. That button name changes to Stop, meaning you can later stop the service by clicking its Stop button.

    Tip You’ll always want the Apache and MySQL apps running, so you can save a bit of time by having the XAMPP Control Panel launch these two apps automatically when you open the program. Click the Config button near the upper-right corner of the XAMPP Control Panel window, select the Apache and MySQL check boxes, and then click Save.

    Remember If when you start an app you run into a Windows Security Alert dialog box similar to the one shown earlier in Figure 2-3, click Show More, select the Private Networks check box, deselect the Public Networks check box, and then click Allow Access.

    Accessing your local web server

    With XAMPP for Windows installed and Apache up and running, congratulations are in order: You have a web server running on your PC! That’s great, but how do you access your shiny, new web server? There are two ways, depending on what you want to do:

    Add files and folders to the web server: Place the files and folders in the htdocs subfolder of your main XAMPP install folder. For example, if you installed XAMPP to C:\xampp, your web server's root folder will be C:\xampp\htdocs.

    View the files and folders on the server: Open your favorite web browser and navigate to the http://localhost address (or to 127.0.0.1, which gets you to the same place). If you have the XAMPP Control Panel open, you can also click the Apache app's Admin button.

    By default, your local website is configured to automatically redirect http://localhost to http://localhost/dashboard/, shown in Figure 2-5, which gives you access to several XAMPP tools.

    You can use the following links, which appear in the page header:

    Apache Friends: Returns you to the main Dashboard page.

    FAQs: Displays a list of XAMPP frequently asked questions.

    How-To Guides: Displays a list of links to step-by-step guides for a number of XAMPP for Windows tasks.

    PHPInfo: Displays a for-geeks-only page of information about the version of PHP that you have installed.

    A screenshot of an X A M P P tools dashboard with web address.

    FIGURE 2-5: The http://localhost/dashboard/ address gives you access to a few XAMPP tools.

    phpMyAdmin: Opens the phpMyAdmin tool, which lets you create and manipulate MariaDB/MySQL databases. You can open phpMyAdmin also by navigating directly to http://localhost/phpmyadmin/, or in the XAMPP Control Panel, by clicking the MySQL app's Admin button. However you get there, just be sure to have the MySQL app running before you open phpMyAdmin.

    Setting Up the XAMPP for OS X Development Environment

    If you’ll be doing your web work on a Mac, I recommend the web development environment XAMPP for OS X (yep, the name uses OS X instead of macOS), which in its most recent version (at least as I write this in mid-2023) requires OS X Snow Leopard (10.6) or later. XAMPP for OS X is packed with programs and features, but you’ll probably only concern yourself with the following:

    Apache: An open-source web server that runs about half of all the websites on Earth

    MariaDB: An open-source server database fully compatible with MySQL (discussed in Book 1, Chapter 1)

    PHP: The server-side programming language that I mention in Book 1, Chapter 1

    phpMyAdmin: An interface that enables you to access and work with MariaDB databases

    The best news of all is XAMPP for OS X is completely free. Nice! To get the show on the road, surf to the Apache Friends website at www.apachefriends.org, and then download the most recent version of XAMPP for OS X.

    Installing XAMPP for OS X

    Once you've downloaded XAMPP for OS X, follow these steps to install it:

    In Finder, double-click the installation file that you downloaded to open the XAMPP installer window.

    Double-click the XAMPP icon.

    If macOS displays a warning that the developer cannot be verified, you need to do the following to get back on track:

    Click Cancel.

    Open System Settings and click Privacy & Security.

    Click the Open Anyway button.

    Enter your Mac administrator credentials, and then click the Modify Settings button.

    In Finder, double-click the XAMPP icon you downloaded earlier to restart the installer.

    When macOS warns you once again that the developer cannot be verified, say It’s cool, bro and click Open.

    Enter your macOS administrator password and then click OK.

    When the XAMPP Setup Wizard appears, click Next.

    In the Select Components dialog, deselect the XAMPP Developer Files check box, as shown in Figure2-6, and then click Next.

    The developer files might sound like they’re right up your alley, but they’re for people who want to add to or modify the code for XAMPP itself.

    In the Installation Directory dialog, click Next.

    Click Next to launch the installation.

    If macOS asks whether you want the application httpd (that would be the Apache web server) to accept incoming network connections, be sure to click Allow.

    Otherwise, your web server won’t work.

    A screenshot of a setup wizard dialog box displays the Select Components page with the X A M P P Developer Files check box deselect.

    FIGURE 2-6: In the Setup wizard dialog, deselect the check box beside XAMPP Developer Files.

    When the install is complete, click Finish.

    If you want to head right into XAMPP Manager, leave the Launch XAMPP check box selected.

    Remember What about the security of your local web server? Fortunately, that’s not an issue because people on your network can’t access your web server. XAMPP is configured by default to be accessible only from the Mac on which it’s installed.

    Running XAMPP Application Manager

    XAMPP Application Manager enables you to start, stop, and configure the XAMPP servers, particularly the Apache web server and the MySQL database system. To launch XAMPP Application Manager, you have two choices:

    If you still have the final Setup wizard dialog onscreen, leave the Launch XAMPP check box selected and click Finish.

    In Finder, open the Applications folder, open the XAMPP folder, and then double-click Manager-OSX.

    XAMPP Application Manager appears. To work with the XAMPP servers, click the Manage Servers tab, shown in Figure 2-7.

    A screenshot of the X A M P P control panel page with the Apache web server highlighted under the manage server options.

    FIGURE 2-7: You use the XAMPP control panel to control and configure services such as Apache and MySQL.

    In the Manage Servers tab, you can perform the following actions:

    Start a server. Click the server and then click Start.

    Start all the servers. Click Start All.

    Restart a server. Click the server and then click Restart.

    Restart all the servers. Click Restart All.

    Stop a server. Click the server and then click Stop.

    Stop all the servers. Click Stop All.

    Accessing your local web server

    With XAMPP for OS X installed and Apache up and running, it’s time for high-fives all around because you have a web server running on your Mac! That’s awesome, but how do you access your web server? There are two ways, depending on what you want to do:

    Add files and folders to the web server: Place the files and folders in the htdocs subfolder of your main XAMPP install folder. To get there, open Applications, open XAMPP, and then double-click htdocs. Alternatively, if you have XAMPP Application Manager open, you can click the Welcome tab, click Open Application Folder, and then open htdocs.

    View the files and folders on the server: Open your favorite web browser and navigate to the http://localhost address (or to http://127.0.0.1, which gets you to the same place). Alternatively, if you have XAMPP Application Manager running, you can click the Welcome tab and then click Go To Application.

    A screenshot of an X A M P P tools dashboard with O S configuration features.

    FIGURE 2-8: The http://localhost/dashboard/ address gives you access to a few XAMPP for OS X features.

    By default, your local website is configured to automatically redirect http://localhost to http://localhost/dashboard/, shown in Figure 2-8, which gives you access to several XAMPP tools.

    You can use the following links in the page header:

    Apache Friends: Returns you to the main Dashboard page.

    FAQs: Displays a list of XAMPP frequently asked questions.

    How-To Guides: Displays a list of links to step-by-step guides for a number of XAMPP for OS X tasks.

    PHPInfo: Displays a for-geeks-only page of information about the version of PHP that you have installed.

    phpMyAdmin: Opens the phpMyAdmin tool, which lets you create and manipulate MariaDB/MySQL databases. You can also open phpMyAdmin by navigating directly to http://localhost/phpmyadmin/. Either way, make sure you have the MySQL Database server running before you open phpMyAdmin.

    Choosing Your Text Editor

    I mention at the beginning of this chapter that all you need to develop web pages is a text editor. However, saying that all you need to code is a text editor is like saying that all you need to live is food: It's certainly true, but more than a little short on specifics. After all, to a large extent, the quality of your life depends on the food you eat. If you survive on nothing but bread and water, well, surviving is all you're doing. What you really need is a balanced diet that supplies all the nutrients your body needs. And pie.

    The bread-and-water version of a text editor is the barebones program that came with your computer: Notepad if you run Windows, or TextEdit if you have a Mac. You can survive as a web developer using these programs, but that’s not living, if you ask me. You need the editing equivalent of vitamins and minerals (and, yes, pie) if you want to flourish as a web coder. These nutrients are the features and tools that are crucial to being an efficient and organized developer:

    Syntax highlighting:Syntax refers to the arrangement of characters and symbols that create correct programming code, and syntax highlighting is an editing feature that color-codes certain syntax elements for easier reading. For example, while regular text might appear black, all HTML tags might be shown in blue and CSS properties might appear red. The best text editors let you choose the syntax colors, either by offering prefab themes or by letting you apply custom colors.

    Line numbers: It might seem like a small thing, but having a text editor that numbers each line, as shown in Figure 2-9, can be a major timesaver. When the web browser alerts you to an error in your code (refer to Book 5, Chapter 2), it gives you an error message and, crucially, the line number of the error. This enables you to quickly locate the culprit and (fingers crossed) fix the problem pronto.

    Code previews: A good text editor will let you view a preview of how your code will look in a web browser. The preview might appear in the same window as your code or in a separate window, and it should update automatically as you modify and save your code.

    Code completion: When you start typing something, this handy feature displays a list of possible code items that complete your typing. You can then select the one you want and press Tab or Enter to add it to your code without having to type the whole thing.

    Spell checking: You always want to put your best web foot forward, which in part means posting pages that don’t contain typos or misspellings. A good text editor has a built-in spell checker that will catch your gaffes before you put your pages on the web.

    A screenshot of a window displays a programming language of text editor features.

    FIGURE 2-9: Line numbers, such as the ones shown here down the left side of the window, are a crucial text editor feature.

    Text processing: The best text editors offer a selection of text processing features, such as automatic indentation of code blocks, converting tabs to spaces and vice versa, shifting chunks of code right or left, removing unneeded spaces at the end of lines, and hiding blocks of code.

    The good news is that there’s no shortage of text editors that support all these features and many more. That’s also the bad news because it means you have a huge range of programs to choose from. To help you get started, here, in alphabetical order, are a few editors to take for test drives:

    Brackets (https://brackets.io/): Available for Windows and Mac. Also free!

    Notepad++ (https://notepad-plus-plus.org/): Available for Windows only. Another freebie.

    Nova (https://nova.app): Available for Mac only. $99, but a free trial is available.

    Sublime Text (www.sublimetext.com): Available for both Windows and Mac. $99, but a free trial is available.

    Visual Studio Code (https://code.visualstudio.com/): Available for Windows and Mac. Why, yes, this one is free, as well.

    Chapter 3

    Finding and Setting Up a Web Host

    IN THIS CHAPTER

    Bullet Understanding web hosting providers

    Bullet Examining the various choices for hosting your site

    Bullet Choosing the host that’s right for you

    Bullet Getting comfortable with your new web home

    Bullet Getting your site files to your web host

    You will end up with better software by releasing as early as practically possible, and then spending the rest of your time iterating rapidly based on real-world feedback. So trust me on this one: Even

    Enjoying the preview?
    Page 1 of 1