5 most common PHP mistakes
PHP is a very unique and effective web language that has been around for a number of years. The problem of writing effective PHP for websites has been around just as long. As with any language this includes computer language there are a variable amount of common mistakes that people need to practice not to do.
One of the most common mistakes, me included, is where to put the correct quotes. For example this code snippet
echo "Hello there.'; // starts with a double-quote, ends with a single-quote.
This particular PHP problem for beginners is tough, because, the PHP is looking for the specific ending double quote. So identifying where to open and close your quotes is the biggest issue with PHP.
Dollar Sign Placement
There are other common mistakes besides the missing quotes in a snippet of code. There are missing dollar signs, incorrect placement of Equal signs, and even misspelled variable names. One basic component for the missing variable is below.
$name = "Mike";
Notice in the snippet above is $name and it is not the same as the $Name so in this example nothing is displayed.
Incorrect Equal Sign Usage
Another example that you may run into is the use of equal signs while using PHP here is an example below
<?php $number = 23; ?>
The value presented is equal to the value of 23
You want to remember as a beginner to draw on a comparison if “IF” in that case you would use it comparable to double equal signs like here below.
echo"23 is in fact equal to 23.";
Missing the ends in PHP script is probably as common as using the quotes ending. Ends are the curly brackets with a slight indent in the middle. The easiest and most reliable method to use in preventing this type of error while writing PHP is to indent your code with spaces or tabs here is a small code example below.
$number = 123;
$name = "Mike";
if ($number == 123)
if ($name == "Mike")
echo "Hi $name!";
$number + $number = $newNumber;
Of course last but not least to PHP beginner mistakes is spelling. When spelling in PHP code it is the best choice to either stick with capitols or with lower case letters never mix both it can be confusing. So, until you get the hang of it always spell using the same type case letters and it will make a smoother transition.
These examples are not to discourage the use of PHP based website design, but, are to help you become aware of some of the more common mistakes that can arise in the beginning. The best thing with any language problems is to practice, practice, and practice. There are a variety of software tools and tutorial to help you identify common mistakes. I found several of them very useful in finding my most common issue with quotes. Try it I’m sure you will agree.
- Complete SEO software solution: backlinks, optimization, analysis, rankings, competitive intelligenc
SEOprofiler.com is a cool online SEO software with backlink analysis, AdWords analysis, competitive intelligence, website optimization, keyword research and much more.
More by this Author
Nicaragua is the land of traditions, history and culture that cannot be found anywhere else in the world. Lets take a look at some of the fun and interesting facts that make Nicaragua one of the best countries in the...
Poverty in Brazil is one of the highest in the world lets explore why..
How to build the perfect dog house for your family friend. With all the comforts of home while he is out side to enjoy a new peaceful place your dog can call home