SlideShare a Scribd company logo
1 of 16
PHP-101
A beginners guide to programming with PHP

By David Menendez
Variables
 A variable is used to represent a piece
  of information in terms that the
  computer can understand
 Types of variables include:
    ◦   Integers = Numbers
    ◦   Strings = Letters and Numbers
    ◦   Boolean = True / False
    ◦   Array = Variable that contains many
        variables
Syntax
 Syntax is simply the language of the
  program
 Syntax is the grammar used to get the
  program to run properly
 Without proper grammar the program
  is doomed to fail!
Syntax Cont.
   Let‟s start a PHP file

    ◦ Begin every PHP file by opening a PHP
      bracket
    ◦ To open the bracket simply start with-
      <?PHP
    ◦ To end the bracket type- ?>
    ◦ Ending Bracket = <?PHP ?>
    ◦ The code goes in-between
Syntax Cont.
   Variable Syntax-
    ◦   How we declare a variable
    ◦   Begin every variable with a dollar sign $
    ◦   Next we add the name- $variable
    ◦   Finally we give it a value- $variable = 50;

   Always remember to end all of your
    statements with a semicolon; It is how
    the program knows the command is
    over
Syntax Cont.
   How to make sure you have declared
    your variable properly
    ◦ Echo = very useful PHP function
    ◦ Echo to show the value of your variable
    ◦ Ex-
      $variable = 5;
      Echo $variable;
      Output on the web page = 5
Databases
 Let‟s connect to a database!
 Start by declaring variables-
    ◦ $connection = mysql_connect();
      This variable is using the mysql_connect
       function to aid us in the connection.
      This function requires 3 inputs within the ().
        Server Name
        User Name
        Password
    ◦ $connection = mysql_connect(„localhost‟,
      „root‟, „password‟);
Databases
   More variables!
    ◦ Select a database-
      $database = mysql_select_db();
    ◦ Completed variable-
      $database =
       mysql_select_db(„database_name‟,
       $connection);
Database Language
 Now we just need to learn a little
  MYSQL to work with databases. Don‟t
  worry, it‟s not hard.
 Pull the information from a table
    ◦ Select all from Table_name(„field_name‟);
    ◦ Now you have all the information from that
      table.
    ◦ Put it in PHP-
      $query = “SELECT all from TABLE („field‟,
       „field‟, field‟);”;
PHP and the Web
 One more vital function for web work
 If / Else statements
 Based on a certain condition
 If X = 1 than go left, If X = 2 go right.
 Syntax-
    ◦ If(condition){outcome};
PHP and the Web
   Let‟s put it all together!
    ◦ Declare your database variables
    ◦ Open up your PHP bracket
    ◦ Time to generate dynamic content!
Dynamic Content
 Use logic and functions to think up
  endless possibilities
 Let‟s start with random pictures
 Important function to making this work
  is the Rand() function
    ◦ Rand() Generates a random number
      between any number you give it.
      Ex- Rand(1,100) will not generate a random
       number between 1 and 100.
Dynamic Content Cont
   Get some images
    ◦ To make this work be sure to end each file
      name with a number. Pic1.jpg, pic2.jpg,
      etc etc
   Declare a variable with rand()
    ◦ $random = rand(1,3);
Dynamic Content Cont
   Put it all together



    ◦   <?php
    ◦   $random = rand(1,3);
    ◦   Echo “Img src=„image” . $random “.jpg‟>”;
    ◦   ?>
Dynamic Content Cont
   So what happened?
    ◦ We declared a variable for a random
      number
    ◦ We used the echo function to show the
      image
    ◦ Now every time this runs it will generate a
      random number, place the number at the
      end of the image and show that image
End
 Now you should have a very basic
  understanding of the PHP language.
 There is a lot more out there to learn
  about PHP and programming.
 If you want to learn more visit
  www.php.net

More Related Content

What's hot

Perl courseparti
Perl coursepartiPerl courseparti
Perl courseparti
ernlow
 

What's hot (20)

Data Types In PHP
Data Types In PHPData Types In PHP
Data Types In PHP
 
PHP-Part4
PHP-Part4PHP-Part4
PHP-Part4
 
PHP Variables and scopes
PHP Variables and scopesPHP Variables and scopes
PHP Variables and scopes
 
Mdst 3559-02-15-php
Mdst 3559-02-15-phpMdst 3559-02-15-php
Mdst 3559-02-15-php
 
PHP-Part3
PHP-Part3PHP-Part3
PHP-Part3
 
PHP-Part2
PHP-Part2PHP-Part2
PHP-Part2
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHP
 
Perl courseparti
Perl coursepartiPerl courseparti
Perl courseparti
 
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysql
 
Loops PHP 04
Loops PHP 04Loops PHP 04
Loops PHP 04
 
php basics
php basicsphp basics
php basics
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
php 2 Function creating, calling, PHP built-in function
php 2 Function creating, calling,PHP built-in functionphp 2 Function creating, calling,PHP built-in function
php 2 Function creating, calling, PHP built-in function
 
Dev traning 2016 basics of PHP
Dev traning 2016   basics of PHPDev traning 2016   basics of PHP
Dev traning 2016 basics of PHP
 
Solution manual of shell programming assignment 2
Solution manual of shell programming assignment 2Solution manual of shell programming assignment 2
Solution manual of shell programming assignment 2
 
Phphacku iitd
Phphacku iitdPhphacku iitd
Phphacku iitd
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
 
Php assignment help
Php assignment helpPhp assignment help
Php assignment help
 
Variables
VariablesVariables
Variables
 
Strings
StringsStrings
Strings
 

Viewers also liked (6)

A guide to using eloquent orm in laravel ♥ scotch
A guide to using eloquent orm in laravel ♥ scotchA guide to using eloquent orm in laravel ♥ scotch
A guide to using eloquent orm in laravel ♥ scotch
 
laravel Elegant artisan by santosh pawar
laravel Elegant artisan by santosh pawarlaravel Elegant artisan by santosh pawar
laravel Elegant artisan by santosh pawar
 
PHP Dependency Management with Composer
PHP Dependency Management with ComposerPHP Dependency Management with Composer
PHP Dependency Management with Composer
 
Multithreading in PHP
Multithreading in PHPMultithreading in PHP
Multithreading in PHP
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
 
Composer | PHP Dependency Manager
Composer | PHP Dependency ManagerComposer | PHP Dependency Manager
Composer | PHP Dependency Manager
 

Similar to Php 101 by David Menendez

Building an e:commerce site with PHP
Building an e:commerce site with PHPBuilding an e:commerce site with PHP
Building an e:commerce site with PHP
webhostingguy
 
HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.js
souridatta
 

Similar to Php 101 by David Menendez (20)

php&mysql with Ethical Hacking
php&mysql with Ethical Hackingphp&mysql with Ethical Hacking
php&mysql with Ethical Hacking
 
Building an e:commerce site with PHP
Building an e:commerce site with PHPBuilding an e:commerce site with PHP
Building an e:commerce site with PHP
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting language
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
 
unit 1.pptx
unit 1.pptxunit 1.pptx
unit 1.pptx
 
lab4_php
lab4_phplab4_php
lab4_php
 
lab4_php
lab4_phplab4_php
lab4_php
 
FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQL
 
Php basic for vit university
Php basic for vit universityPhp basic for vit university
Php basic for vit university
 
Php
PhpPhp
Php
 
PHP - Web Development
PHP - Web DevelopmentPHP - Web Development
PHP - Web Development
 
Free PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in IndiaFree PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in India
 
PHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginnersPHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginners
 
HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.js
 
Materi Dasar PHP
Materi Dasar PHPMateri Dasar PHP
Materi Dasar PHP
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Php basics
Php basicsPhp basics
Php basics
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 

Recently uploaded

QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
httgc7rh9c
 

Recently uploaded (20)

Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 

Php 101 by David Menendez

  • 1. PHP-101 A beginners guide to programming with PHP By David Menendez
  • 2. Variables  A variable is used to represent a piece of information in terms that the computer can understand  Types of variables include: ◦ Integers = Numbers ◦ Strings = Letters and Numbers ◦ Boolean = True / False ◦ Array = Variable that contains many variables
  • 3. Syntax  Syntax is simply the language of the program  Syntax is the grammar used to get the program to run properly  Without proper grammar the program is doomed to fail!
  • 4. Syntax Cont.  Let‟s start a PHP file ◦ Begin every PHP file by opening a PHP bracket ◦ To open the bracket simply start with- <?PHP ◦ To end the bracket type- ?> ◦ Ending Bracket = <?PHP ?> ◦ The code goes in-between
  • 5. Syntax Cont.  Variable Syntax- ◦ How we declare a variable ◦ Begin every variable with a dollar sign $ ◦ Next we add the name- $variable ◦ Finally we give it a value- $variable = 50;  Always remember to end all of your statements with a semicolon; It is how the program knows the command is over
  • 6. Syntax Cont.  How to make sure you have declared your variable properly ◦ Echo = very useful PHP function ◦ Echo to show the value of your variable ◦ Ex-  $variable = 5;  Echo $variable;  Output on the web page = 5
  • 7. Databases  Let‟s connect to a database!  Start by declaring variables- ◦ $connection = mysql_connect();  This variable is using the mysql_connect function to aid us in the connection.  This function requires 3 inputs within the ().  Server Name  User Name  Password ◦ $connection = mysql_connect(„localhost‟, „root‟, „password‟);
  • 8. Databases  More variables! ◦ Select a database-  $database = mysql_select_db(); ◦ Completed variable-  $database = mysql_select_db(„database_name‟, $connection);
  • 9. Database Language  Now we just need to learn a little MYSQL to work with databases. Don‟t worry, it‟s not hard.  Pull the information from a table ◦ Select all from Table_name(„field_name‟); ◦ Now you have all the information from that table. ◦ Put it in PHP-  $query = “SELECT all from TABLE („field‟, „field‟, field‟);”;
  • 10. PHP and the Web  One more vital function for web work  If / Else statements  Based on a certain condition  If X = 1 than go left, If X = 2 go right.  Syntax- ◦ If(condition){outcome};
  • 11. PHP and the Web  Let‟s put it all together! ◦ Declare your database variables ◦ Open up your PHP bracket ◦ Time to generate dynamic content!
  • 12. Dynamic Content  Use logic and functions to think up endless possibilities  Let‟s start with random pictures  Important function to making this work is the Rand() function ◦ Rand() Generates a random number between any number you give it.  Ex- Rand(1,100) will not generate a random number between 1 and 100.
  • 13. Dynamic Content Cont  Get some images ◦ To make this work be sure to end each file name with a number. Pic1.jpg, pic2.jpg, etc etc  Declare a variable with rand() ◦ $random = rand(1,3);
  • 14. Dynamic Content Cont  Put it all together ◦ <?php ◦ $random = rand(1,3); ◦ Echo “Img src=„image” . $random “.jpg‟>”; ◦ ?>
  • 15. Dynamic Content Cont  So what happened? ◦ We declared a variable for a random number ◦ We used the echo function to show the image ◦ Now every time this runs it will generate a random number, place the number at the end of the image and show that image
  • 16. End  Now you should have a very basic understanding of the PHP language.  There is a lot more out there to learn about PHP and programming.  If you want to learn more visit www.php.net