Jump to content

echo "Hello World!"; :)


jazza96

Recommended Posts

Hello! 

My name is Jarrod and I am 18 and live in Australia. I have only just started coding in the past 3 months and PHP is my first language.

 

I have just completed the O'Riley book 'PHP, MYSQL, Javascript, CSS and HTML5'.

Edited by jazza96
Link to comment
Share on other sites

Welcome Jarrod

 

They still sell that book? Hopefully you'll learn better practices here.

 

Here is the best place to learn php, browse through it as if you never read that book.

php.net tutorial

 

Familiarize yourself with the extensions and their functions, is plenty of examples there.

http://php.net/manual/en/extensions.alphabetical.php

Link to comment
Share on other sites

Welcome Jarrod

 

They still sell that book? Hopefully you'll learn better practices here.

 

Here is the best place to learn php, browse through it as if you never read that book.

php.net tutorial

 

Familiarize yourself with the extensions and their functions, is plenty of examples there.

http://php.net/manual/en/extensions.alphabetical.php

 

 

Yes, here it is on Amazon.

http://www.amazon.com/Learning-MySQL-JavaScript-HTML5-Step-/dp/1491949465/ref=sr_1_1?s=books&ie=UTF8&qid=1419850564&sr=1-1&keywords=php

 

Have you heard bad things about the book? 

Link to comment
Share on other sites

Well with any book or tutorial is sometimes not the best way or bad practices.

I read an older version many years ago, hopefully they changed a lot of it.

If you use it as a beginners guide and not a bible while continuing to learn will be ok.

 

Sometimes even comes down to preferences of the programmer.

Here are some of mine and personal advice.

 

Turn on error reporting and display all errors during development, log the errors in production sites.

 

We are in the era of PDO and prepared statements, if have the choice go PDO

It's good to get familiar with old or outdated code so you can spot it or know how to fix it.

 

Get your full idea planned out in steps, figure out how you may go about it, see if is any alternate or better ways.

If is any trouble areas...try to work those out first to see if is feasible.

Failing at something is also learning, don't get stressed or upset.

Sometimes a few minutes of thought can save you hours/days/months of headaches later on.

 

I prefer procedural over oop most of the time.

Resembles a lot of other coding languages that have been doing for 35 years and makes me more proficient

oop has it's uses though, so would be good to learn it once get a firm grasp on procedural

Please don't mix oop and procedural.

 

I heavily comment to remind myself years later or possibly someone else

Also handy to comment end braces if need to add or remove some code there

Name variables, functions, classes, methods, etc relative to what they actually are, not meaningless letters and numbers that anyone but you knew what they stood for at the time.

I prefer to use _ for $mulitple_variable_names and Upper first letter multiple words for myFunctionNames

Do lots of spacing to try and organize or section the code

Don't make functions if know are only gonna use it once or just to include it.

Piles of includes is bad.

Never iframe, file_get_contents or curl something from your own site, just include it.

Although require_once may be a tad slower it makes the code a lot less prone to errors, if write code well use include

Relative paths seems like is more efficient and easier...but can cause many issues, I'll take absolute urls and full paths any day.

Try not to do that spaghetti code coming in and out of html and php, logic then display, do all processing above and html on the bottom.

Function before beauty is my style. make sure it all works, then dress it up, you may scrap the idea and wasted time.

If you need to make a search index for your defines...you probably did it wrong.

Always check if a variable is set before using it.

Define empty arrays prior to questionably using them.

Trimming a variable will ensure is no unwanted whitespace

Don't come up with your own security rules unless you absolutely know what are doing, use tried and proven methods.

Store sensitive data a non public folder

Never store plaintext passwords, not in cookies,sessions,file or database, not ever

Don't repeat yourself, if a function or making an array will save you lots of repetitive code, by all means do it.

If you have a page full of elseif's, a switch is probably better

Look into data normalization

UTF-8 is your friend

The ci in database collations means case insensitive, use it

Even better...don't uppercase databases, columns or tables in the database

Always filter/sanitize/escape anything going into your database

check for exact data types you expect

Don't use for or foreach loops with mysql results, that's what while is for

Don't so sql queries in loops.

If you have to do a few sql queries to get some data, you can most likely use join or rewrite your query

Don't select * in a query unless you plan to use it all, otherwise only fetch what are going to use

For mysql query results, fetch_array will return the numeric index and also associative array , if you don't need the numeric index use fetch_assoc because will only be the associative array

There was a few rare instances where I had to use $_REQUEST, try to use the servers request type you selected

Additional checking for errors within your code is helpful

Never output anything before header()

Register globals was never good to use

Print or echo, I always use echo because it can do more and why bother to mix them

Use print_r to show a pretty array just to check code works, var_dump is more useful

Stick with full <?php ?> tags as <? ?> short tags not always enabled on servers.

Always use curly braces, will help maintain your code better and not forget when actually need one.

I personally use four spaces for indentation

Use a good ide or coding editor with color highlighting and formatting, I use notepad plus

One line per statement is fine, more readable code, don't jumble it all up one line.

Single quote,double quote, types of concatenation, I usually stick to doubles and use curly braces, but sometimes not if am sure will be no variables.

Don't use addslashes.

Don't use $_SERVER['php_self'], forget it exists.

Quote your variable keys

 

That's all I have for now, am sure I missed many.

Link to comment
Share on other sites

Well with any book or tutorial is sometimes not the best way or bad practices.

I read an older version many years ago, hopefully they changed a lot of it.

If you use it as a beginners guide and not a bible while continuing to learn will be ok.

 

Sometimes even comes down to preferences of the programmer.

Here are some of mine and personal advice.

 

Turn on error reporting and display all errors during development, log the errors in production sites.

 

We are in the era of PDO and prepared statements, if have the choice go PDO

It's good to get familiar with old or outdated code so you can spot it or know how to fix it.

 

Get your full idea planned out in steps, figure out how you may go about it, see if is any alternate or better ways.

If is any trouble areas...try to work those out first to see if is feasible.

Failing at something is also learning, don't get stressed or upset.

Sometimes a few minutes of thought can save you hours/days/months of headaches later on.

 

I prefer procedural over oop most of the time.

Resembles a lot of other coding languages that have been doing for 35 years and makes me more proficient

oop has it's uses though, so would be good to learn it once get a firm grasp on procedural

Please don't mix oop and procedural.

 

I heavily comment to remind myself years later or possibly someone else

Also handy to comment end braces if need to add or remove some code there

Name variables, functions, classes, methods, etc relative to what they actually are, not meaningless letters and numbers that anyone but you knew what they stood for at the time.

I prefer to use _ for $mulitple_variable_names and Upper first letter multiple words for myFunctionNames

Do lots of spacing to try and organize or section the code

Don't make functions if know are only gonna use it once or just to include it.

Piles of includes is bad.

Never iframe, file_get_contents or curl something from your own site, just include it.

Although require_once may be a tad slower it makes the code a lot less prone to errors, if write code well use include

Relative paths seems like is more efficient and easier...but can cause many issues, I'll take absolute urls and full paths any day.

Try not to do that spaghetti code coming in and out of html and php, logic then display, do all processing above and html on the bottom.

Function before beauty is my style. make sure it all works, then dress it up, you may scrap the idea and wasted time.

If you need to make a search index for your defines...you probably did it wrong.

Always check if a variable is set before using it.

Define empty arrays prior to questionably using them.

Trimming a variable will ensure is no unwanted whitespace

Don't come up with your own security rules unless you absolutely know what are doing, use tried and proven methods.

Store sensitive data a non public folder

Never store plaintext passwords, not in cookies,sessions,file or database, not ever

Don't repeat yourself, if a function or making an array will save you lots of repetitive code, by all means do it.

If you have a page full of elseif's, a switch is probably better

Look into data normalization

UTF-8 is your friend

The ci in database collations means case insensitive, use it

Even better...don't uppercase databases, columns or tables in the database

Always filter/sanitize/escape anything going into your database

check for exact data types you expect

Don't use for or foreach loops with mysql results, that's what while is for

Don't so sql queries in loops.

If you have to do a few sql queries to get some data, you can most likely use join or rewrite your query

Don't select * in a query unless you plan to use it all, otherwise only fetch what are going to use

For mysql query results, fetch_array will return the numeric index and also associative array , if you don't need the numeric index use fetch_assoc because will only be the associative array

There was a few rare instances where I had to use $_REQUEST, try to use the servers request type you selected

Additional checking for errors within your code is helpful

Never output anything before header()

Register globals was never good to use

Print or echo, I always use echo because it can do more and why bother to mix them

Use print_r to show a pretty array just to check code works, var_dump is more useful

Stick with full <?php ?> tags as <? ?> short tags not always enabled on servers.

Always use curly braces, will help maintain your code better and not forget when actually need one.

I personally use four spaces for indentation

Use a good ide or coding editor with color highlighting and formatting, I use notepad plus

One line per statement is fine, more readable code, don't jumble it all up one line.

Single quote,double quote, types of concatenation, I usually stick to doubles and use curly braces, but sometimes not if am sure will be no variables.

Don't use addslashes.

Don't use $_SERVER['php_self'], forget it exists.

Quote your variable keys

 

That's all I have for now, am sure I missed many.

 

 

Thanks for those tips. 

I am currently building a basic CRUD program and I am learning quite a lot just from building something.. 

Edited by jazza96
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.