So I was up late last night making some tweaks to my blog theme and realized that now would probably be a good time to share some of my PHP knowledge with new Domainers. PHP is an essential language to know when working with WordPress and comes-in handy for building your own sites as well. The great thing about PHP is that it is nowhere near as complicated as a programming language like C++ or Java so you can learn and begin using PHP very quickly.
So for the month of June I will be doing a four-part series on PHP that will get you up and running without having to read one of those “Learn PHP in 24-hour” books. I think PHP is an essential language for any Domainer that is also a developer. As more and more Domainers start blogging or developing mini-sites PHP will continue to become increasingly important. If you’ve ever been confused by the inner-working of your WordPress themes I hope this helps to allow you to customize your themes beyond the WordPress GUI.
So let’s get started with the first lesson!
You can add PHP to an existing website easily by simply typing when you want to start writing “<?PHP” before your code and then
"?>" when you are done with your code. That’s it – put your PHP code between these two tags and you are ready to go. So time to learn your first PHP function – print. The code snipped below will write – “Hello Domaining World” on your site:
print “Hello Domaining World”;
If you put this into an HTML document and upload it to your server (given that is supports PHP which just about every hosting company has pre-installed) then you’ve just written your first working PHP code! Pat yourself on the back and we’ll move-onto something a bit more interesting.
Let’s cut to the chase and make something interactive. Where PHP really shines is interacting with HMTL forms. Now I’ll show you how to make a simple form on your website that you can then interact with using PHP – first let’s start with a basic HTML form:
<form method = “POST” action = “domainvestors_form.php”>
Name: <input type = “text” name = “username”>
Domain: <input type = “text” name = “domain”>
<input type = “submit” value = “Submit”>
This creates a simple HTML form that asks the user for a name and a domain. Now we’ll write a simple PHP script to interact with it – in this case the script will be in a file named domainvestors_form.php:<?php
print “Your name is: “;
print “Your domain is: “;
This code will print your name and domain. The only new function you need to learn to interact with forms is $_POST[‘variable_name’] where variable_name is whatever you specified as the name for the particular input in your form.
As you can see – PHP really isn’t that complicated. If you’ve made it this far you now know how to add PHP to your site as well as access data from a form. There are a few more things you’ll need to know in order to really start digging-into your WordPress theme files, but I’ll save that for the following lessons. For now – open-up your favorite text-editor and try the script I’ve written above. If you have a hosting account with someone like GoDaddy then PHP is already installed and ready to go.
In the next lesson I’ll teach you a few more basic PHP concepts and then show you some examples of how these can be applied to understanding and editing your WordPress themes! If you don’t know HTML – it is MUCH easier than you might think. I have taught people with almost no computer experience how to build a webpage by writing HTML in a simple text-editor in under an hour. There isn’t much to it and you’ll be surprised about how much more you can do with your domains once you know the basics.
If you like this post, then consider subscribing to my full feed RSS
Also – please share your opinion and comment! If you like this post, hate this post, want to know more – comment and let me know!