SlideShare a Scribd company logo
PHP & MySQL Corporate Training Material Design & Created  by Karma E Shop
What is PHP Used For? PHP  is a general-purpose server-side  scripting language  originally designed for  web development  to produce  dynamic web pages  PHP can interact with MySQL databases
What is PHP? PHP ==  ‘ Hypertext Preprocessor ’ Open-source, server-side scripting language Used to generate dynamic web-pages PHP scripts reside between reserved PHP tags This allows the programmer to embed PHP scripts within HTML pages
What is PHP (cont’d) Interpreted language, scripts are parsed at run-time rather than compiled beforehand Executed on the server-side Source-code not visible by client ‘ View Source ’  in browsers does not display the PHP code Various built-in functions allow for fast development Compatible with many popular databases
What does PHP code look like? Structurally similar to C/C++ Supports procedural and object-oriented paradigm (to some degree) All PHP statements end with a semi-colon Each PHP script must be enclosed in the reserved PHP tag <?php … ?>
Comments in PHP Standard C, C++, and shell comment symbols // C++ and Java-style comment # Shell-style comments /* C-style comments These can span multiple lines */
Variables in PHP PHP variables must begin with a  “ $ ”  sign Case-sensitive ($Foo != $foo != $fOo) Global and locally-scoped variables Global variables can be used anywhere Local variables restricted to a function or class Certain variable names reserved by PHP Form variables ($_POST, $_GET) Server variables ($_SERVER) Etc.
Variable usage <?php $foo = 25; // Numerical variable $bar = “Hello”; // String variable $foo = ($foo * 7); // Multiplies foo by 7 $bar = ($bar * 7); // Invalid expression  ?>
Echo The PHP command  ‘ echo ’  is used to output the parameters passed to it The typical usage for this is to send data to the client ’ s web-browser Syntax void  echo  (string arg 1  [, string arg n ...])  In practice, arguments are not passed in parentheses since  echo  is a language construct rather than an actual function
Echo example Notice  how echo  ‘ 5x5=$foo ’  outputs $foo rather than replacing it with 25 Strings in single quotes ( ‘   ’ ) are not interpreted or evaluated by PHP  This is true for both variables and character escape-sequences (such as  “ \n ”  or  “ \\ ” ) <?php $foo = 25; // Numerical variable $bar = “Hello”; // String variable echo $bar; // Outputs Hello echo $foo,$bar; // Outputs 25Hello echo “5x5=”,$foo; // Outputs 5x5=25 echo “5x5=$foo”; // Outputs 5x5=25 echo ‘5x5=$foo’; // Outputs 5x5=$foo ?>
Arithmetic Operations $a - $b  // subtraction $a * $b // multiplication $a / $b // division $a += 5 // $a = $a+5 Also works for *= and /= <?php $a=15; $b=30; $total=$a+$b; Print $total; Print “<p><h1>$total</h1>”; // total is 45 ?>
Concatenation Use a period to join strings into one. <?php $string1=“Hello”; $string2=“PHP”; $string3=$string1 . “ ” . $string2; Print $string3; ?>   Hello PHP
Escaping the Character If the string has a set of double quotation marks that must remain visible, use the \ [backslash] before the quotation marks to ignore and display them. <?php $heading=“\”Computer Science\””; Print $heading; ?>   “ Computer Science”
PHP Control Structures Control Structures: Are the structures within a language that allow us to control the flow of execution through a program or script. Grouped into conditional (branching) structures (e.g. if/else) and repetition structures (e.g. while loops). Example if/else if/else statement: if ($foo == 0) { echo ‘The variable foo is equal to 0’; } else if (($foo > 0) && ($foo <= 5)) {   echo ‘The variable foo is between 1 and 5’; } else {   echo ‘The variable foo is equal to ‘.$foo; }
If ... Else... If (condition) { Statements; } Else { Statement; } <?php If($user==“John”) { Print “Hello John.”; } Else { Print “You are not John.”; } ?>   No THEN in PHP
While Loops While (condition) { Statements; } <?php $count=0; While($count<3) { Print “hello PHP. ”; $count += 1; // $count = $count + 1; // or // $count++; ?>   hello PHP. hello PHP. hello PHP.
Date Display $datedisplay=date(“yyyy/m/d”); Print $datedisplay; # If the date is April 1 st , 2009 # It would display as 2009/4/1 2009/4/1 $datedisplay=date(“l, F m, Y”); Print $datedisplay; # If the date is April 1 st , 2009 # Wednesday, April 1, 2009 Wednesday, April 1, 2009
Month, Day & Date Format Symbols M Jan F January m 01 n 1 Day of Month d 01 Day of Month J 1 Day of Week l Monday Day of Week D Mon
Functions Functions MUST be defined before then can be called Function headers are of the format Note that no return type is specified Unlike variables, function names are not case sensitive (foo( … ) == Foo( … ) == FoO( … )) function functionName($arg_1, $arg_2, …, $arg_n)
Functions example <?php // This is a function function foo($arg_1, $arg_2) {   $arg_2 = $arg_1 * $arg_2;    return $arg_2; }  $result_1 = foo(12, 3); // Store the function  echo $result_1; // Outputs 36 echo foo(12, 3); // Outputs 36 ?>
Include Files Include “opendb.php”; Include “closedb.php”; This inserts files; the code in files will be inserted into current code. This will provide useful and protective means once you connect to a database, as well as for other repeated functions. Include (“footer.php”); The file footer.php might look like: <hr SIZE=11 NOSHADE WIDTH=“100%”> <i>Copyright  © 2008-2010 KSU </i></font><br> <i>ALL RIGHTS RESERVED</i></font><br> <i>URL: http://www.kent.edu</i></font><br>
PHP - Forms Access to the HTTP POST and GET data is simple in PHP The global variables $_POST[] and $_GET[] contain the request data   <?php if ($_POST[&quot;submit&quot;]) echo &quot;<h2>You clicked Submit!</h2>&quot;; else if ($_POST[&quot;cancel&quot;]) echo &quot;<h2>You clicked Cancel!</h2>&quot;; ?> <form action=&quot;form.php&quot; method=&quot;post&quot;> <input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot;> <input type=&quot;submit&quot; name=&quot;cancel&quot; value=&quot;Cancel&quot;> </form> http://www.cs.kent.edu/~nruan/form.php
WHY PHP – Sessions ? Whenever you want to create a  website  that allows you to store and display information about a user, determine which user groups a person belongs to, utilize permissions on your  website  or you just want to do something cool on your site,  PHP's Sessions  are vital to  each  of these features.  Cookies are about 30% unreliable right now and it's getting worse every day. More and more web browsers are starting to come with security and privacy settings and people browsing the net these days are starting to frown upon Cookies because they store information on their local computer that they do not want stored there. PHP has a great set of functions that can achieve the same results of Cookies and more without storing information on the user's computer. PHP Sessions store the information on the web server in a location that you chose in special files. These files are connected to the user's web browser via the server and a special ID called a &quot;Session ID&quot;. This is nearly 99% flawless in operation and it is virtually invisible to the user.
PHP - Sessions Sessions store their identifier in a cookie in the client’s browser Every page that uses session data must be proceeded by the  session_start()  function Session variables are then set and retrieved by accessing the global  $_SESSION[] Save it as  session.php   <?php session_start(); if (!$_SESSION[&quot;count&quot;]) $_SESSION[&quot;count&quot;] = 0; if ($_GET[&quot;count&quot;] == &quot;yes&quot;) $_SESSION[&quot;count&quot;] = $_SESSION[&quot;count&quot;] + 1; echo &quot;<h1>&quot;.$_SESSION[&quot;count&quot;].&quot;</h1>&quot;; ?> <a href=&quot;session.php?count=yes&quot;>Click here to count</a> http://www.cs.kent.edu/~nruan/session.php
Avoid Error PHP - Sessions PHP Example:  <?php  echo &quot;Look at this nasty error below:<br />&quot;;  session_start();  ?>  Error!  PHP Example:  <?php  session_start();  echo &quot;Look at this nasty error below:&quot;;  ?>  Correct Warning: Cannot send  session  cookie - headers already sent by (output started at session_header_error/session_error.php:2) in session_header_error/session_error.php on line 3 Warning: Cannot send  session  cache limiter - headers already sent (output started at session_header_error/session_error.php:2) in session_header_error/session_error.php on line 3
Destroy PHP - Sessions Destroying a Session why it is necessary to destroy a  session  when the  session  will get destroyed when the user closes their browser. Well, imagine that you had a  session  registered called &quot;access_granted&quot; and you were using that to determine if the user was logged into your site based upon a username and password. Anytime you have a login feature, to make the users feel better, you should have a logout feature as well. That's where this cool function called  session_destroy()  comes in handy.  session_destroy()  will completely demolish your  session  (no, the computer won't blow up or self destruct) but it just deletes the  session  files and clears any trace of that session. NOTE: If you are using the $_SESSION superglobal  array , you must clear the  array  values first, then run session_destroy. Here's how we use  session_destroy ():
Destroy PHP - Sessions <?php  // start the session  session_start();  header(&quot;Cache-control: private&quot;); //IE 6 Fix  $_SESSION =  array ();  session_destroy();  echo &quot;<strong>Step 5 - Destroy This Session </strong><br />&quot;;  if($_SESSION['name']){      echo &quot;The  session  is still active&quot;;  } else {      echo &quot;Ok, the  session  is no longer active! <br />&quot;;      echo &quot;<a href=\&quot;page1.php\&quot;><< Go Back Step 1</a>&quot;;  }  ?>
Easy learning Syntax Perl- and C-like syntax. Relatively easy to learn. Large function library Embedded directly into HTML Interpreted, no need to compile Open Source server-side scripting language designed specifically for the web.   PHP Overview
PHP Overview (cont.) Conceived in 1994, now used on +10 million web sites. Outputs not only HTML but can output XML, images (JPG & PNG), PDF files and even Flash movies all generated on the fly. Can write these files to the file system. Supports a wide-range of databases (20+ODBC). PHP also has support for talking to other services using protocols such as LDAP, IMAP, SNMP, NNTP, POP3, HTTP.
Save as sample.php: <! –  sample.php --> <html><body> <strong>Hello World!</strong><br /> <?php  echo  “ <h2>Hello, World</h2> ” ; ?> <?php $myvar = &quot;Hello World&quot;; echo $myvar;   ?> </body></html> First PHP script http://www.cs.kent.edu/~nruan/sample.php
Example – show data in the tables Function: list all tables in your database. Users can select one of tables, and show all contents in this table. second.php showtable.php
second.php <html><head><title>MySQL Table Viewer</title></head><body> <?php // change the value of $dbuser and $dbpass to your username and password $dbhost = 'hercules.cs.kent.edu:3306'; $dbuser = 'nruan'; $dbpass = ‘*****************’; $dbname = $dbuser; $table = 'account'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if (!$conn) { die('Could not connect: ' . mysql_error()); } if (!mysql_select_db($dbname)) die(&quot;Can't select database&quot;);
second.php (cont.) $result = mysql_query(&quot;SHOW TABLES&quot;); if (!$result) { die(&quot;Query to show fields from table failed&quot;); } $num_row = mysql_num_rows($result); echo &quot;<h1>Choose one table:<h1>&quot;;  echo &quot;<form action=\&quot;showtable.php\&quot; method=\&quot;POST\&quot;>&quot;; echo &quot;<select name=\&quot;table\&quot; size=\&quot;1\&quot; Font size=\&quot;+2\&quot;>&quot;; for($i=0; $i<$num_row; $i++) { $tablename=mysql_fetch_row($result); echo &quot;<option value=\&quot;{$tablename[0]}\&quot; >{$tablename[0]}</option>&quot;; } echo &quot;</select>&quot;; echo &quot;<div><input type=\&quot;submit\&quot; value=\&quot;submit\&quot;></div>&quot;; echo &quot;</form>&quot;; mysql_free_result($result); mysql_close($conn); ?> </body></html>
showtable.php <html><head> <title>MySQL Table Viewer</title> </head> <body> <?php $dbhost = 'hercules.cs.kent.edu:3306'; $dbuser = 'nruan'; $dbpass = ‘**********’; $dbname = 'nruan'; $table = $_POST[“table”]; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if (!$conn)  die('Could not connect: ' . mysql_error()); if (!mysql_select_db($dbname))  die(&quot;Can't select database&quot;); $result = mysql_query(&quot;SELECT * FROM {$table}&quot;); if (!$result)  die(&quot;Query to show fields from table failed!&quot; . mysql_error());
showtable.php (cont.) $fields_num = mysql_num_fields($result); echo &quot;<h1>Table: {$table}</h1>&quot;; echo &quot;<table border='1'><tr>&quot;; // printing table headers for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); echo &quot;<td><b>{$field->name}</b></td>&quot;; } echo &quot;</tr>\n&quot;; while($row = mysql_fetch_row($result)) { echo &quot;<tr>&quot;; // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row as $cell) echo &quot;<td>$cell</td>&quot;; echo &quot;</tr>\n&quot;; } mysql_free_result($result); mysql_close($conn); ?> </body></html>
Functions Covered mysql_connect() mysql_select_db() include() mysql_query() mysql_num_rows() mysql_fetch_array() mysql_close()
History of PHP PHP began in 1995 when Rasmus Lerdorf developed a Perl/CGI script toolset he called the Personal Home Page or PHP PHP 2 released 1997 (PHP now stands for Hypertex Processor). Lerdorf developed it further, using C instead PHP3 released in 1998 (50,000 users) PHP4 released in 2000 (3.6 million domains). Considered debut of functional language and including Perl parsing, with other major features PHP5.0.0 released July 13, 2004 (113 libraries>1,000 functions with extensive object-oriented programming) PHP5.0.5 released Sept. 6, 2005 for maintenance and bug fixes
Recommended Texts for Learning PHP Larry Ullman’s books from the Visual Quickpro series PHP & MySQL for Dummies Beginning PHP 5 and MySQL: From Novice to Professional by W. Jason Gilmore (This is more advanced and dense than the others, but great to read once you’ve finished the easier books. One of the best definition/description of object oriented programming I’ve read)
PHP References http://www.php.net  <-- php home page http://www.phpbuilder.com/ http://www.devshed.com/ http://www.phpmyadmin.net/ http://www.hotscripts.com/PHP/ http://geocities.com/stuprojects/ChatroomDescription.htm  http://www.academic.marist.edu/~kbhkj/chatroom/chatroom.htm  http://www.aus-etrade.com/Scripts/php.php http://www.codeproject.com/asp/CDIChatSubmit.asp http://www.php.net/downloads  <-- php download page http://www.php.net/manual/en/install.windows.php  <-- php installation manual http://php.resourceindex.com/  <-- PHP resources like sample programs, text book references, etc. http://www.daniweb.com/techtalkforums/forum17.html    php forums

More Related Content

What's hot (20)

PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
Vibrant Technologies & Computers
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
NexThoughts Technologies
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
Priya Goyal
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
Nidhi mishra
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
Computer Hardware & Trouble shooting
 
Php introduction
Php introductionPhp introduction
Php introduction
krishnapriya Tadepalli
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
shreesenthil
 
Form Handling using PHP
Form Handling using PHPForm Handling using PHP
Form Handling using PHP
Nisa Soomro
 
php
phpphp
php
ajeetjhajharia
 
PHP Cookies and Sessions
PHP Cookies and SessionsPHP Cookies and Sessions
PHP Cookies and Sessions
Nisa Soomro
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
Manish Bothra
 
PHP variables
PHP  variablesPHP  variables
PHP variables
Siddique Ibrahim
 
Javascript
JavascriptJavascript
Javascript
mussawir20
 
Scripting languages
Scripting languagesScripting languages
Scripting languages
teach4uin
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
Dhani Ahmad
 
PHP Loops and PHP Forms
PHP  Loops and PHP FormsPHP  Loops and PHP Forms
PHP Loops and PHP Forms
M.Zalmai Rahmani
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and require
TheCreativedev Blog
 
Php
PhpPhp
Php
Shyam Khant
 

Viewers also liked (6)

Php Ppt
Php PptPhp Ppt
Php Ppt
vsnmurthy
 
Beginners PHP Tutorial
Beginners PHP TutorialBeginners PHP Tutorial
Beginners PHP Tutorial
alexjones89
 
Mysql & Php
Mysql & PhpMysql & Php
Mysql & Php
Inbal Geffen
 
Loops PHP 04
Loops PHP 04Loops PHP 04
Loops PHP 04
mohamedsaad24
 
PHP Summer Training Presentation
PHP Summer Training PresentationPHP Summer Training Presentation
PHP Summer Training Presentation
Nitesh Sharma
 
Ad

Similar to Php mysql ppt (20)

slidesharenew1
slidesharenew1slidesharenew1
slidesharenew1
truptitasol
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
omprakash_bagrao_prdxn
 
Php mysql
Php mysqlPhp mysql
Php mysql
Alebachew Zewdu
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
Prof.Dharmishtha R. Chaudhari
 
Learning of Php and My SQL Tutorial | For Beginners
Learning of Php and My SQL Tutorial | For BeginnersLearning of Php and My SQL Tutorial | For Beginners
Learning of Php and My SQL Tutorial | For Beginners
Ratnesh Pandey
 
Php My SQL Tutorial | beginning
Php My SQL Tutorial | beginningPhp My SQL Tutorial | beginning
Php My SQL Tutorial | beginning
CRM Manager | Developer @ Websoles Strategic Digital Solutions
 
Php Tutorial | Introduction Demo | Basics
 Php Tutorial | Introduction Demo | Basics Php Tutorial | Introduction Demo | Basics
Php Tutorial | Introduction Demo | Basics
Shubham Kumar Singh
 
Php mysql
Php mysqlPhp mysql
Php mysql
Abu Bakar
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
Web development
Web developmentWeb development
Web development
Seerat Bakhtawar
 
Introduction To Php For Wit2009
Introduction To Php For Wit2009Introduction To Php For Wit2009
Introduction To Php For Wit2009
cwarren
 
What Is Php
What Is PhpWhat Is Php
What Is Php
AVC
 
Php with my sql
Php with my sqlPhp with my sql
Php with my sql
husnara mohammad
 
Php
PhpPhp
Php
TSUBHASHRI
 
Php
PhpPhp
Php
TSUBHASHRI
 
Php
PhpPhp
Php
TSUBHASHRI
 
Introducation to php for beginners
Introducation to php for beginners Introducation to php for beginners
Introducation to php for beginners
musrath mohammad
 
Php
PhpPhp
Php
WAHEEDA ROOHILLAH
 
Babitha5.php
Babitha5.phpBabitha5.php
Babitha5.php
banubabitha
 
Babitha5.php
Babitha5.phpBabitha5.php
Babitha5.php
banubabitha
 
Ad

Recently uploaded (20)

DIGIPIN : The new Digital Address system in India - How It can Help Pharma In...
DIGIPIN : The new Digital Address system in India - How It can Help Pharma In...DIGIPIN : The new Digital Address system in India - How It can Help Pharma In...
DIGIPIN : The new Digital Address system in India - How It can Help Pharma In...
Satya Mahesh Kallakuru
 
Automotive Filter Test ..pdf
Automotive Filter Test             ..pdfAutomotive Filter Test             ..pdf
Automotive Filter Test ..pdf
Test Master
 
Deutsche Bank Access Global Consumer Conference 2025
Deutsche Bank Access Global Consumer Conference 2025Deutsche Bank Access Global Consumer Conference 2025
Deutsche Bank Access Global Consumer Conference 2025
SYYIR
 
Oleksandr Osypenko: Професійна етика та відповідальність (UA)
Oleksandr Osypenko: Професійна етика та відповідальність (UA)Oleksandr Osypenko: Професійна етика та відповідальність (UA)
Oleksandr Osypenko: Професійна етика та відповідальність (UA)
Lviv Startup Club
 
Extending Infrastructure Life with Protective Coatings
Extending Infrastructure Life with Protective CoatingsExtending Infrastructure Life with Protective Coatings
Extending Infrastructure Life with Protective Coatings
rahil wit
 
What is Interior designing(introduction).pdf
What is Interior designing(introduction).pdfWhat is Interior designing(introduction).pdf
What is Interior designing(introduction).pdf
bhatiagitali
 
20250506_A. Stotz All Weather Strategy - Performance review April 2025
20250506_A. Stotz All Weather Strategy - Performance review April 202520250506_A. Stotz All Weather Strategy - Performance review April 2025
20250506_A. Stotz All Weather Strategy - Performance review April 2025
FINNOMENAMarketing
 
Top Essential OpenCart Extensions for Developers in 2025.pdf
Top Essential OpenCart Extensions for Developers in 2025.pdfTop Essential OpenCart Extensions for Developers in 2025.pdf
Top Essential OpenCart Extensions for Developers in 2025.pdf
Hornet Dynamics
 
TriStar Gold Corporate Presentation - June 2025
TriStar Gold Corporate Presentation - June 2025TriStar Gold Corporate Presentation - June 2025
TriStar Gold Corporate Presentation - June 2025
Adnet Communications
 
Commercial Banks Management Unit-2 Risks Faced by Commercial Banks.pptx
Commercial Banks Management Unit-2 Risks Faced by Commercial Banks.pptxCommercial Banks Management Unit-2 Risks Faced by Commercial Banks.pptx
Commercial Banks Management Unit-2 Risks Faced by Commercial Banks.pptx
aachalmagar86
 
Facemask Filter test .pdf
Facemask Filter test                .pdfFacemask Filter test                .pdf
Facemask Filter test .pdf
Test Master
 
A Certificate Programme on ISO56000 Series_Ver 4_Level 1.pdf
A Certificate Programme on ISO56000 Series_Ver 4_Level 1.pdfA Certificate Programme on ISO56000 Series_Ver 4_Level 1.pdf
A Certificate Programme on ISO56000 Series_Ver 4_Level 1.pdf
Innomantra
 
Scott Damron Embracing the Thrill of Rock Climbing and Cycling in Georgia.docx
Scott Damron  Embracing the Thrill of Rock Climbing and Cycling in Georgia.docxScott Damron  Embracing the Thrill of Rock Climbing and Cycling in Georgia.docx
Scott Damron Embracing the Thrill of Rock Climbing and Cycling in Georgia.docx
ScottDamron1
 
HVAC Filter Test .pdf
HVAC Filter Test                    .pdfHVAC Filter Test                    .pdf
HVAC Filter Test .pdf
Test Master
 
Eco Packing experts Australia Catalogues
Eco Packing experts Australia CataloguesEco Packing experts Australia Catalogues
Eco Packing experts Australia Catalogues
Samsmith644393
 
Comprehensive Guide to Managing E-Wallets in Direct Sales
Comprehensive Guide to Managing E-Wallets in Direct SalesComprehensive Guide to Managing E-Wallets in Direct Sales
Comprehensive Guide to Managing E-Wallets in Direct Sales
Epixel MLM Software
 
Enhancing MLM Platforms Through Advanced Communication Tools
Enhancing MLM Platforms Through Advanced Communication ToolsEnhancing MLM Platforms Through Advanced Communication Tools
Enhancing MLM Platforms Through Advanced Communication Tools
Epixel MLM Software
 
Dr. Enrique Segura Ense Group - A Collector Of Italian Cars.pdf
Dr. Enrique Segura Ense Group - A Collector Of Italian Cars.pdfDr. Enrique Segura Ense Group - A Collector Of Italian Cars.pdf
Dr. Enrique Segura Ense Group - A Collector Of Italian Cars.pdf
Dr. Enrique Segura Ense Group
 
Adam and Daniel Kaplan - A Head For Entrepreneurship
Adam and Daniel Kaplan - A Head For EntrepreneurshipAdam and Daniel Kaplan - A Head For Entrepreneurship
Adam and Daniel Kaplan - A Head For Entrepreneurship
Adam and Daniel Kaplan
 
The Essential Guide to Using Weed Mats Effectively.pdf
The Essential Guide to Using Weed Mats Effectively.pdfThe Essential Guide to Using Weed Mats Effectively.pdf
The Essential Guide to Using Weed Mats Effectively.pdf
dmktg41singhal
 
DIGIPIN : The new Digital Address system in India - How It can Help Pharma In...
DIGIPIN : The new Digital Address system in India - How It can Help Pharma In...DIGIPIN : The new Digital Address system in India - How It can Help Pharma In...
DIGIPIN : The new Digital Address system in India - How It can Help Pharma In...
Satya Mahesh Kallakuru
 
Automotive Filter Test ..pdf
Automotive Filter Test             ..pdfAutomotive Filter Test             ..pdf
Automotive Filter Test ..pdf
Test Master
 
Deutsche Bank Access Global Consumer Conference 2025
Deutsche Bank Access Global Consumer Conference 2025Deutsche Bank Access Global Consumer Conference 2025
Deutsche Bank Access Global Consumer Conference 2025
SYYIR
 
Oleksandr Osypenko: Професійна етика та відповідальність (UA)
Oleksandr Osypenko: Професійна етика та відповідальність (UA)Oleksandr Osypenko: Професійна етика та відповідальність (UA)
Oleksandr Osypenko: Професійна етика та відповідальність (UA)
Lviv Startup Club
 
Extending Infrastructure Life with Protective Coatings
Extending Infrastructure Life with Protective CoatingsExtending Infrastructure Life with Protective Coatings
Extending Infrastructure Life with Protective Coatings
rahil wit
 
What is Interior designing(introduction).pdf
What is Interior designing(introduction).pdfWhat is Interior designing(introduction).pdf
What is Interior designing(introduction).pdf
bhatiagitali
 
20250506_A. Stotz All Weather Strategy - Performance review April 2025
20250506_A. Stotz All Weather Strategy - Performance review April 202520250506_A. Stotz All Weather Strategy - Performance review April 2025
20250506_A. Stotz All Weather Strategy - Performance review April 2025
FINNOMENAMarketing
 
Top Essential OpenCart Extensions for Developers in 2025.pdf
Top Essential OpenCart Extensions for Developers in 2025.pdfTop Essential OpenCart Extensions for Developers in 2025.pdf
Top Essential OpenCart Extensions for Developers in 2025.pdf
Hornet Dynamics
 
TriStar Gold Corporate Presentation - June 2025
TriStar Gold Corporate Presentation - June 2025TriStar Gold Corporate Presentation - June 2025
TriStar Gold Corporate Presentation - June 2025
Adnet Communications
 
Commercial Banks Management Unit-2 Risks Faced by Commercial Banks.pptx
Commercial Banks Management Unit-2 Risks Faced by Commercial Banks.pptxCommercial Banks Management Unit-2 Risks Faced by Commercial Banks.pptx
Commercial Banks Management Unit-2 Risks Faced by Commercial Banks.pptx
aachalmagar86
 
Facemask Filter test .pdf
Facemask Filter test                .pdfFacemask Filter test                .pdf
Facemask Filter test .pdf
Test Master
 
A Certificate Programme on ISO56000 Series_Ver 4_Level 1.pdf
A Certificate Programme on ISO56000 Series_Ver 4_Level 1.pdfA Certificate Programme on ISO56000 Series_Ver 4_Level 1.pdf
A Certificate Programme on ISO56000 Series_Ver 4_Level 1.pdf
Innomantra
 
Scott Damron Embracing the Thrill of Rock Climbing and Cycling in Georgia.docx
Scott Damron  Embracing the Thrill of Rock Climbing and Cycling in Georgia.docxScott Damron  Embracing the Thrill of Rock Climbing and Cycling in Georgia.docx
Scott Damron Embracing the Thrill of Rock Climbing and Cycling in Georgia.docx
ScottDamron1
 
HVAC Filter Test .pdf
HVAC Filter Test                    .pdfHVAC Filter Test                    .pdf
HVAC Filter Test .pdf
Test Master
 
Eco Packing experts Australia Catalogues
Eco Packing experts Australia CataloguesEco Packing experts Australia Catalogues
Eco Packing experts Australia Catalogues
Samsmith644393
 
Comprehensive Guide to Managing E-Wallets in Direct Sales
Comprehensive Guide to Managing E-Wallets in Direct SalesComprehensive Guide to Managing E-Wallets in Direct Sales
Comprehensive Guide to Managing E-Wallets in Direct Sales
Epixel MLM Software
 
Enhancing MLM Platforms Through Advanced Communication Tools
Enhancing MLM Platforms Through Advanced Communication ToolsEnhancing MLM Platforms Through Advanced Communication Tools
Enhancing MLM Platforms Through Advanced Communication Tools
Epixel MLM Software
 
Dr. Enrique Segura Ense Group - A Collector Of Italian Cars.pdf
Dr. Enrique Segura Ense Group - A Collector Of Italian Cars.pdfDr. Enrique Segura Ense Group - A Collector Of Italian Cars.pdf
Dr. Enrique Segura Ense Group - A Collector Of Italian Cars.pdf
Dr. Enrique Segura Ense Group
 
Adam and Daniel Kaplan - A Head For Entrepreneurship
Adam and Daniel Kaplan - A Head For EntrepreneurshipAdam and Daniel Kaplan - A Head For Entrepreneurship
Adam and Daniel Kaplan - A Head For Entrepreneurship
Adam and Daniel Kaplan
 
The Essential Guide to Using Weed Mats Effectively.pdf
The Essential Guide to Using Weed Mats Effectively.pdfThe Essential Guide to Using Weed Mats Effectively.pdf
The Essential Guide to Using Weed Mats Effectively.pdf
dmktg41singhal
 

Php mysql ppt

  • 1. PHP & MySQL Corporate Training Material Design & Created by Karma E Shop
  • 2. What is PHP Used For? PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages PHP can interact with MySQL databases
  • 3. What is PHP? PHP == ‘ Hypertext Preprocessor ’ Open-source, server-side scripting language Used to generate dynamic web-pages PHP scripts reside between reserved PHP tags This allows the programmer to embed PHP scripts within HTML pages
  • 4. What is PHP (cont’d) Interpreted language, scripts are parsed at run-time rather than compiled beforehand Executed on the server-side Source-code not visible by client ‘ View Source ’ in browsers does not display the PHP code Various built-in functions allow for fast development Compatible with many popular databases
  • 5. What does PHP code look like? Structurally similar to C/C++ Supports procedural and object-oriented paradigm (to some degree) All PHP statements end with a semi-colon Each PHP script must be enclosed in the reserved PHP tag <?php … ?>
  • 6. Comments in PHP Standard C, C++, and shell comment symbols // C++ and Java-style comment # Shell-style comments /* C-style comments These can span multiple lines */
  • 7. Variables in PHP PHP variables must begin with a “ $ ” sign Case-sensitive ($Foo != $foo != $fOo) Global and locally-scoped variables Global variables can be used anywhere Local variables restricted to a function or class Certain variable names reserved by PHP Form variables ($_POST, $_GET) Server variables ($_SERVER) Etc.
  • 8. Variable usage <?php $foo = 25; // Numerical variable $bar = “Hello”; // String variable $foo = ($foo * 7); // Multiplies foo by 7 $bar = ($bar * 7); // Invalid expression ?>
  • 9. Echo The PHP command ‘ echo ’ is used to output the parameters passed to it The typical usage for this is to send data to the client ’ s web-browser Syntax void echo (string arg 1 [, string arg n ...]) In practice, arguments are not passed in parentheses since echo is a language construct rather than an actual function
  • 10. Echo example Notice how echo ‘ 5x5=$foo ’ outputs $foo rather than replacing it with 25 Strings in single quotes ( ‘ ’ ) are not interpreted or evaluated by PHP This is true for both variables and character escape-sequences (such as “ \n ” or “ \\ ” ) <?php $foo = 25; // Numerical variable $bar = “Hello”; // String variable echo $bar; // Outputs Hello echo $foo,$bar; // Outputs 25Hello echo “5x5=”,$foo; // Outputs 5x5=25 echo “5x5=$foo”; // Outputs 5x5=25 echo ‘5x5=$foo’; // Outputs 5x5=$foo ?>
  • 11. Arithmetic Operations $a - $b // subtraction $a * $b // multiplication $a / $b // division $a += 5 // $a = $a+5 Also works for *= and /= <?php $a=15; $b=30; $total=$a+$b; Print $total; Print “<p><h1>$total</h1>”; // total is 45 ?>
  • 12. Concatenation Use a period to join strings into one. <?php $string1=“Hello”; $string2=“PHP”; $string3=$string1 . “ ” . $string2; Print $string3; ?> Hello PHP
  • 13. Escaping the Character If the string has a set of double quotation marks that must remain visible, use the \ [backslash] before the quotation marks to ignore and display them. <?php $heading=“\”Computer Science\””; Print $heading; ?> “ Computer Science”
  • 14. PHP Control Structures Control Structures: Are the structures within a language that allow us to control the flow of execution through a program or script. Grouped into conditional (branching) structures (e.g. if/else) and repetition structures (e.g. while loops). Example if/else if/else statement: if ($foo == 0) { echo ‘The variable foo is equal to 0’; } else if (($foo > 0) && ($foo <= 5)) { echo ‘The variable foo is between 1 and 5’; } else { echo ‘The variable foo is equal to ‘.$foo; }
  • 15. If ... Else... If (condition) { Statements; } Else { Statement; } <?php If($user==“John”) { Print “Hello John.”; } Else { Print “You are not John.”; } ?> No THEN in PHP
  • 16. While Loops While (condition) { Statements; } <?php $count=0; While($count<3) { Print “hello PHP. ”; $count += 1; // $count = $count + 1; // or // $count++; ?> hello PHP. hello PHP. hello PHP.
  • 17. Date Display $datedisplay=date(“yyyy/m/d”); Print $datedisplay; # If the date is April 1 st , 2009 # It would display as 2009/4/1 2009/4/1 $datedisplay=date(“l, F m, Y”); Print $datedisplay; # If the date is April 1 st , 2009 # Wednesday, April 1, 2009 Wednesday, April 1, 2009
  • 18. Month, Day & Date Format Symbols M Jan F January m 01 n 1 Day of Month d 01 Day of Month J 1 Day of Week l Monday Day of Week D Mon
  • 19. Functions Functions MUST be defined before then can be called Function headers are of the format Note that no return type is specified Unlike variables, function names are not case sensitive (foo( … ) == Foo( … ) == FoO( … )) function functionName($arg_1, $arg_2, …, $arg_n)
  • 20. Functions example <?php // This is a function function foo($arg_1, $arg_2) { $arg_2 = $arg_1 * $arg_2;   return $arg_2; } $result_1 = foo(12, 3); // Store the function echo $result_1; // Outputs 36 echo foo(12, 3); // Outputs 36 ?>
  • 21. Include Files Include “opendb.php”; Include “closedb.php”; This inserts files; the code in files will be inserted into current code. This will provide useful and protective means once you connect to a database, as well as for other repeated functions. Include (“footer.php”); The file footer.php might look like: <hr SIZE=11 NOSHADE WIDTH=“100%”> <i>Copyright © 2008-2010 KSU </i></font><br> <i>ALL RIGHTS RESERVED</i></font><br> <i>URL: http://www.kent.edu</i></font><br>
  • 22. PHP - Forms Access to the HTTP POST and GET data is simple in PHP The global variables $_POST[] and $_GET[] contain the request data <?php if ($_POST[&quot;submit&quot;]) echo &quot;<h2>You clicked Submit!</h2>&quot;; else if ($_POST[&quot;cancel&quot;]) echo &quot;<h2>You clicked Cancel!</h2>&quot;; ?> <form action=&quot;form.php&quot; method=&quot;post&quot;> <input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot;> <input type=&quot;submit&quot; name=&quot;cancel&quot; value=&quot;Cancel&quot;> </form> http://www.cs.kent.edu/~nruan/form.php
  • 23. WHY PHP – Sessions ? Whenever you want to create a website that allows you to store and display information about a user, determine which user groups a person belongs to, utilize permissions on your website or you just want to do something cool on your site, PHP's Sessions are vital to each of these features. Cookies are about 30% unreliable right now and it's getting worse every day. More and more web browsers are starting to come with security and privacy settings and people browsing the net these days are starting to frown upon Cookies because they store information on their local computer that they do not want stored there. PHP has a great set of functions that can achieve the same results of Cookies and more without storing information on the user's computer. PHP Sessions store the information on the web server in a location that you chose in special files. These files are connected to the user's web browser via the server and a special ID called a &quot;Session ID&quot;. This is nearly 99% flawless in operation and it is virtually invisible to the user.
  • 24. PHP - Sessions Sessions store their identifier in a cookie in the client’s browser Every page that uses session data must be proceeded by the session_start() function Session variables are then set and retrieved by accessing the global $_SESSION[] Save it as session.php <?php session_start(); if (!$_SESSION[&quot;count&quot;]) $_SESSION[&quot;count&quot;] = 0; if ($_GET[&quot;count&quot;] == &quot;yes&quot;) $_SESSION[&quot;count&quot;] = $_SESSION[&quot;count&quot;] + 1; echo &quot;<h1>&quot;.$_SESSION[&quot;count&quot;].&quot;</h1>&quot;; ?> <a href=&quot;session.php?count=yes&quot;>Click here to count</a> http://www.cs.kent.edu/~nruan/session.php
  • 25. Avoid Error PHP - Sessions PHP Example: <?php echo &quot;Look at this nasty error below:<br />&quot;; session_start(); ?> Error! PHP Example: <?php session_start(); echo &quot;Look at this nasty error below:&quot;; ?> Correct Warning: Cannot send session cookie - headers already sent by (output started at session_header_error/session_error.php:2) in session_header_error/session_error.php on line 3 Warning: Cannot send session cache limiter - headers already sent (output started at session_header_error/session_error.php:2) in session_header_error/session_error.php on line 3
  • 26. Destroy PHP - Sessions Destroying a Session why it is necessary to destroy a session when the session will get destroyed when the user closes their browser. Well, imagine that you had a session registered called &quot;access_granted&quot; and you were using that to determine if the user was logged into your site based upon a username and password. Anytime you have a login feature, to make the users feel better, you should have a logout feature as well. That's where this cool function called session_destroy() comes in handy. session_destroy() will completely demolish your session (no, the computer won't blow up or self destruct) but it just deletes the session files and clears any trace of that session. NOTE: If you are using the $_SESSION superglobal array , you must clear the array values first, then run session_destroy. Here's how we use session_destroy ():
  • 27. Destroy PHP - Sessions <?php // start the session session_start(); header(&quot;Cache-control: private&quot;); //IE 6 Fix $_SESSION = array (); session_destroy(); echo &quot;<strong>Step 5 - Destroy This Session </strong><br />&quot;; if($_SESSION['name']){     echo &quot;The session is still active&quot;; } else {     echo &quot;Ok, the session is no longer active! <br />&quot;;     echo &quot;<a href=\&quot;page1.php\&quot;><< Go Back Step 1</a>&quot;; } ?>
  • 28. Easy learning Syntax Perl- and C-like syntax. Relatively easy to learn. Large function library Embedded directly into HTML Interpreted, no need to compile Open Source server-side scripting language designed specifically for the web. PHP Overview
  • 29. PHP Overview (cont.) Conceived in 1994, now used on +10 million web sites. Outputs not only HTML but can output XML, images (JPG & PNG), PDF files and even Flash movies all generated on the fly. Can write these files to the file system. Supports a wide-range of databases (20+ODBC). PHP also has support for talking to other services using protocols such as LDAP, IMAP, SNMP, NNTP, POP3, HTTP.
  • 30. Save as sample.php: <! – sample.php --> <html><body> <strong>Hello World!</strong><br /> <?php echo “ <h2>Hello, World</h2> ” ; ?> <?php $myvar = &quot;Hello World&quot;; echo $myvar; ?> </body></html> First PHP script http://www.cs.kent.edu/~nruan/sample.php
  • 31. Example – show data in the tables Function: list all tables in your database. Users can select one of tables, and show all contents in this table. second.php showtable.php
  • 32. second.php <html><head><title>MySQL Table Viewer</title></head><body> <?php // change the value of $dbuser and $dbpass to your username and password $dbhost = 'hercules.cs.kent.edu:3306'; $dbuser = 'nruan'; $dbpass = ‘*****************’; $dbname = $dbuser; $table = 'account'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if (!$conn) { die('Could not connect: ' . mysql_error()); } if (!mysql_select_db($dbname)) die(&quot;Can't select database&quot;);
  • 33. second.php (cont.) $result = mysql_query(&quot;SHOW TABLES&quot;); if (!$result) { die(&quot;Query to show fields from table failed&quot;); } $num_row = mysql_num_rows($result); echo &quot;<h1>Choose one table:<h1>&quot;; echo &quot;<form action=\&quot;showtable.php\&quot; method=\&quot;POST\&quot;>&quot;; echo &quot;<select name=\&quot;table\&quot; size=\&quot;1\&quot; Font size=\&quot;+2\&quot;>&quot;; for($i=0; $i<$num_row; $i++) { $tablename=mysql_fetch_row($result); echo &quot;<option value=\&quot;{$tablename[0]}\&quot; >{$tablename[0]}</option>&quot;; } echo &quot;</select>&quot;; echo &quot;<div><input type=\&quot;submit\&quot; value=\&quot;submit\&quot;></div>&quot;; echo &quot;</form>&quot;; mysql_free_result($result); mysql_close($conn); ?> </body></html>
  • 34. showtable.php <html><head> <title>MySQL Table Viewer</title> </head> <body> <?php $dbhost = 'hercules.cs.kent.edu:3306'; $dbuser = 'nruan'; $dbpass = ‘**********’; $dbname = 'nruan'; $table = $_POST[“table”]; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if (!$conn) die('Could not connect: ' . mysql_error()); if (!mysql_select_db($dbname)) die(&quot;Can't select database&quot;); $result = mysql_query(&quot;SELECT * FROM {$table}&quot;); if (!$result) die(&quot;Query to show fields from table failed!&quot; . mysql_error());
  • 35. showtable.php (cont.) $fields_num = mysql_num_fields($result); echo &quot;<h1>Table: {$table}</h1>&quot;; echo &quot;<table border='1'><tr>&quot;; // printing table headers for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); echo &quot;<td><b>{$field->name}</b></td>&quot;; } echo &quot;</tr>\n&quot;; while($row = mysql_fetch_row($result)) { echo &quot;<tr>&quot;; // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row as $cell) echo &quot;<td>$cell</td>&quot;; echo &quot;</tr>\n&quot;; } mysql_free_result($result); mysql_close($conn); ?> </body></html>
  • 36. Functions Covered mysql_connect() mysql_select_db() include() mysql_query() mysql_num_rows() mysql_fetch_array() mysql_close()
  • 37. History of PHP PHP began in 1995 when Rasmus Lerdorf developed a Perl/CGI script toolset he called the Personal Home Page or PHP PHP 2 released 1997 (PHP now stands for Hypertex Processor). Lerdorf developed it further, using C instead PHP3 released in 1998 (50,000 users) PHP4 released in 2000 (3.6 million domains). Considered debut of functional language and including Perl parsing, with other major features PHP5.0.0 released July 13, 2004 (113 libraries>1,000 functions with extensive object-oriented programming) PHP5.0.5 released Sept. 6, 2005 for maintenance and bug fixes
  • 38. Recommended Texts for Learning PHP Larry Ullman’s books from the Visual Quickpro series PHP & MySQL for Dummies Beginning PHP 5 and MySQL: From Novice to Professional by W. Jason Gilmore (This is more advanced and dense than the others, but great to read once you’ve finished the easier books. One of the best definition/description of object oriented programming I’ve read)
  • 39. PHP References http://www.php.net <-- php home page http://www.phpbuilder.com/ http://www.devshed.com/ http://www.phpmyadmin.net/ http://www.hotscripts.com/PHP/ http://geocities.com/stuprojects/ChatroomDescription.htm http://www.academic.marist.edu/~kbhkj/chatroom/chatroom.htm http://www.aus-etrade.com/Scripts/php.php http://www.codeproject.com/asp/CDIChatSubmit.asp http://www.php.net/downloads <-- php download page http://www.php.net/manual/en/install.windows.php <-- php installation manual http://php.resourceindex.com/ <-- PHP resources like sample programs, text book references, etc. http://www.daniweb.com/techtalkforums/forum17.html  php forums