Your SlideShare is downloading. ×
0
1. Current trends – WEB Tech…
1. Current trends – WEB Tech…
2. PHP & MySQL – An Introduction
2. PHP & MySQL – An Introduct...
Usage of server-side programming
languages for websites

PHP is now installed on more than

20 million websites and 1 mill...
Usage of client-side programming
languages for websites

Source : http://w3techs.com
Usage of markup languages for
websites

Source : http://w3techs.com
What is XHTML ?
1. XHTML is an Extensible HyperText Markup Language
2. XHTML is a combination of HTML and XML
(EXtensible ...
Usage of JavaScript libraries for
websites

Source : http://w3techs.com
PHP: Hypertext Preprocessor
• PHP was created by Rasmus Lerdorf in 1994.
• PHP is a recursive acronym for “PHP: Hypertext
...
PHP Programming Paradigms
Uses both procedural and object oriented
paradigms

• Procedural PHP
 Has been in use since the...
What is PHP Good For?
• It is great for complex web page designs
 E-commerce sites with heavy traffic (Amazon,Flipkart)
...
PHP Introduction
•

PHP is known as a server-sided language. That's because
the PHP doesn't get executed on your computer,...
PHP Introduction
• PHP code is interpreted by a web server with a PHP
processor module which generates the resulting web p...
PHP Introduction
Why is PHP used?
1. Easy to Use
Code is embedded into HTML. The PHP code is enclosed in
special start and end tags that al...
Why is PHP used?
2.Cross Platform
Runs on almost any Web server on several operating
systems. One of the strongest feature...
Why is PHP used?
3.Cost Benefits
PHP is free. Open source code means that the entire
PHP community will contribute towards...
Getting Started PHP Hello World

Above is the PHP source code.
PHP Hello World
It renders as HTML that looks like this:
PHP Comments
• All php files are saved with extension .php
• The can be written in notepad or any text
editor
• Single lin...
Variables
 Variables start with a $ symbol - $name , $age , $city
 A variable name can only contain alpha-numeric
charac...
PHP Conditional Statements
• if statement - use this statement to execute some code only if
a specified condition is true
...
Conditions
• If else
if(condition) {….}
elseif(condition) {….}
else { ….}

• Switch case
switch(var)
{
case c1: statements...
PHP Arrays
• An array variable is a storage area holding
a number or text. The problem is, a variable
will hold only one v...
PHP Arrays
In PHP, there are three kind of arrays:
• Numeric array - An array with a numeric
index
• Associative array - A...
PHP Arrays
• Numeric array - An array with a numeric
index
$students_array[0] = “Rohan”;
$students_array[1] = “Dhruba”;
$s...
PHP Arrays
• Associative array - An array where each ID
key is associated with a value
$marks[“Rohan”] = 90;
$marks[“Dhrub...
PHP Arrays
• Multidimensional array - An array containing
one or more arrays
$shop = array(

array("rose", 1.25 , 15),
arr...
PHP Loops
• while - loops through a block of code while a
specified condition is true
• do...while - loops through a block...
Loops

•

for
for(intialisation;condition;increment/decrement)
{ //do this code }
• while
while ( conditional statement is...
Operators
Operators are used to operate on values.
There are four classifications of operators:

 Arithmetic
 Assignment...
PHP Operators
PHP Operators
PHP Operators
PHP Operators
Functions and Parameters
• PHP functions need to be defined with key
word function
• It can have zero or more values (para...
Functions
• Parameter less function
<?php
function sayHi()
{
echo “hi”;
}

?>
This can be called as <?php sayHi(); ?>
in t...
Functions
• Parameterized function
<?php
function greet($name)
{
echo “Hello “ . $name;
}

?>
This can be called <?php gre...
Functions
• Function returning value
<?php
function add($a,$b)
{
return ($a + $b);
}

?>
When called like <?php echo add(1...
Example
The following example shows how to display
content according to the day of the week.
0 (for Sunday) through 6 (for...
Complete Example

• Step 1: Universal header and footer in a single file
•

Create a file called header.php. This file wil...
Complete Example
• Step 2: Universal header and footer in a single file
• Next, create a file called footer.php. This file...
Complete Example
•
•

Step 3: Universal header and footer in a single file
This is the basic template that you will use on...
Example ( Benefits )
Any changes to header or footer only require editing of a single file. These
changes will take effect...
PHP Forms - $_GET Function
 The built-in $_GET function is used to collect values from a form sent
with method=“GET”
<for...
PHP Forms - $_POST Function
• The built-in $_POST function is used to collect
values from a form sent with method=“POST".
...
PHP Database Handling
• PHP can connect to
– MySQL
– Access and other databases
like Oracle, postgre sql, SQL
Server etc

...
What is MySQL
• MySQL is a database system used on the web that
runs on a server
• MySQL is ideal for both small and large...
Companies using MySQL
MySQL Connection
• mysql_connect(dbserver,userid,password)
is used for connecting to MySQL dbserver using a userid
and pas...
MySQL Select DB
• mysql_select_db(database,connection)
Parameter

Description

database

Required. Specifies the database ...
MySQL Execute Query
mysql_query(sql query, connection);
This will execute the sql statement on the database and store the
...
Our Task
Registration and Login
• We will develop a registration and login system
using PHP and MySQL
• We will need two forms, php...
Registration and Login
• Database - name “pailan”
• Table – name “mst_facehook”
Field
id
email
password
gender
city

Type
...
Registration Page
Login Page
SHOUBHIK ROY / SANDEEP BAJORIA

email : info@brainware-baguiati.com
M : +91 98319 28362 / +91 98309 36993
web : www.brainw...
PHP MySQL Workshop - facehook
Upcoming SlideShare
Loading in...5
×

PHP MySQL Workshop - facehook

2,843

Published on

For PCMT Students

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,843
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
75
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • int value can be -2147483648 these are 11 digits so default size is 11
    unsigned int does not allow negative numbers so default size is 10
    An INT will always be 4 bytes no matter what length is specified.
    TINYINT = 1 byte
    SMALLINT = 2 bytes
    MEDIUMINT = 3 bytes
    INT = 4 bytes
    BIGINT = 8 bytes.
  • Transcript of "PHP MySQL Workshop - facehook"

    1. 1. 1. Current trends – WEB Tech… 1. Current trends – WEB Tech… 2. PHP & MySQL – An Introduction 2. PHP & MySQL – An Introduction 3. Getting started 3. Getting started 4. Examples 4. Examples 5. Simple Registration & Login app 5. Simple Registration & Login app
    2. 2. Usage of server-side programming languages for websites PHP is now installed on more than 20 million websites and 1 million web servers. servers Source : http://w3techs.com
    3. 3. Usage of client-side programming languages for websites Source : http://w3techs.com
    4. 4. Usage of markup languages for websites Source : http://w3techs.com
    5. 5. What is XHTML ? 1. XHTML is an Extensible HyperText Markup Language 2. XHTML is a combination of HTML and XML (EXtensible Markup Language) 3. XHTML is almost identical to HTML 4.01 but a stricter cleaner version. The major differences are:  XHTML elements must be properly nested.  XHTML elements must always be closed.  XHTML elements must be in lowercase.  XHTML documents must have one root element.
    6. 6. Usage of JavaScript libraries for websites Source : http://w3techs.com
    7. 7. PHP: Hypertext Preprocessor • PHP was created by Rasmus Lerdorf in 1994. • PHP is a recursive acronym for “PHP: Hypertext Preprocessor”. • PHP is powerful server-side scripting language for creating dynamic and interactive websites. • PHP is perfectly suited for Web development and can be embedded directly into the HTML code. • The PHP syntax is very similar to JavaScript, Perl and C Language.
    8. 8. PHP Programming Paradigms Uses both procedural and object oriented paradigms • Procedural PHP  Has been in use since the creation of PHP, its primary paradigm.  Allows for easy and quick learning of the PHP language.  Similar to other popular languages such as Visual Basic, C++, and Fortran. • Object Oriented PHP  Similar to Java
    9. 9. What is PHP Good For? • It is great for complex web page designs  E-commerce sites with heavy traffic (Amazon,Flipkart)  Secure websites (Paypal)  Email web hosts (Gmail)  Database management and search (FaceBook, naukri, Wikipedia , Flickr )  Most content management systems such as WordPress, Drupal, and Joomla are all based on PHP.
    10. 10. PHP Introduction • PHP is known as a server-sided language. That's because the PHP doesn't get executed on your computer, but on the computer you requested the page from. The results are then handed over to you, and displayed in your browser. • PHP supports many databases ( MySQL, Informix, Oracle, Sybase, PostgreSQL, Generic ODBC, etc.) • It is an open source software, which is widely used and free to download and use.
    11. 11. PHP Introduction • PHP code is interpreted by a web server with a PHP processor module which generates the resulting web page . • PHP code is executed on the server, generating HTML which is then sent to the client. The client would receive the results of running that script, but would not know what the underlying code was.
    12. 12. PHP Introduction
    13. 13. Why is PHP used? 1. Easy to Use Code is embedded into HTML. The PHP code is enclosed in special start and end tags that allow you to jump into and out of "PHP mode". <html> <head> <title>Brainware Baguiati PHP Example</title> </head> <body> <?php echo "Hi, I am a PHP script !"; ?> </body> </html>
    14. 14. Why is PHP used? 2.Cross Platform Runs on almost any Web server on several operating systems. One of the strongest features is the wide range of supported databases. Web Servers: Apache, Microsoft IIS ,nGinx, etc Operating Systems: Linux, Mac OSX, Windows Supported Databases: IBM DB2, Informix, Ingres, MySQL, ODBC, Oracle, PostgreSQL, SQLite, Sybase
    15. 15. Why is PHP used? 3.Cost Benefits PHP is free. Open source code means that the entire PHP community will contribute towards bug fixes. There are several add-on technologies (libraries) for PHP that are also free. Software Free Platform Free (Linux) Development Tools Free PHP Coder, jEdit , Notepad++
    16. 16. Getting Started PHP Hello World Above is the PHP source code.
    17. 17. PHP Hello World It renders as HTML that looks like this:
    18. 18. PHP Comments • All php files are saved with extension .php • The can be written in notepad or any text editor • Single line comment // this is single line comment • Multi line comment /*…. This is a multi line comment */
    19. 19. Variables  Variables start with a $ symbol - $name , $age , $city  A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )  In PHP, a variable does not need to be declared before adding a value to it.  PHP is loosely typed language. There is no strict data typing. PHP automatically converts the variable to the correct data type, depending on its value.  Variables are CASE SENSITIVE. ($y and $Y are two different variables)
    20. 20. PHP Conditional Statements • if statement - use this statement to execute some code only if a specified condition is true • if...else statement - use this statement to execute some code if a condition is true and another code if the condition is false • if...elseif....else statement - use this statement to select one of several blocks of code to be executed • switch statement - use this statement to select one of many blocks of code to be executed
    21. 21. Conditions • If else if(condition) {….} elseif(condition) {….} else { ….} • Switch case switch(var) { case c1: statements;break …… Default: statements; break; }
    22. 22. PHP Arrays • An array variable is a storage area holding a number or text. The problem is, a variable will hold only one value. • An array is a special variable, which can store multiple values in one single variable.
    23. 23. PHP Arrays In PHP, there are three kind of arrays: • Numeric array - An array with a numeric index • Associative array - An array where each ID key is associated with a value • Multidimensional array - An array containing one or more arrays
    24. 24. PHP Arrays • Numeric array - An array with a numeric index $students_array[0] = “Rohan”; $students_array[1] = “Dhruba”; $students_array[2] = “Rina”; $students_array[3] = “Tanya”; echo "Two of my students are " . $students_array[0] . " and " . $students_array[1];
    25. 25. PHP Arrays • Associative array - An array where each ID key is associated with a value $marks[“Rohan”] = 90; $marks[“Dhruba”] = 80; $marks[“Rina”] = 65; $marks[“Tanya”] = 88; echo "Rohan has secured : " . $marks["Rohan"] . "<br />"; echo "Dhruba has secured :" . $marks["Dhruba"] . "<br />"; echo "Rina has secured : " . $marks["Rina"] . "<br />"; echo "Tanya has secured :" . $marks["Tanya"];
    26. 26. PHP Arrays • Multidimensional array - An array containing one or more arrays $shop = array( array("rose", 1.25 , 15), array("daisy", 0.75 , 25), array("orchid", 1.15 , 7) ); echo $shop[0][0]." costs ".$shop[0][1]." and you get ".$shop[0][2]."<br />"; echo $shop[1][0]." costs ".$shop[1][1]." and you get ".$shop[1][2]."<br />"; echo $shop[2][0]." costs ".$shop[2][1]." and you get ".$shop[2][2]."<br />";
    27. 27. PHP Loops • while - loops through a block of code while a specified condition is true • do...while - loops through a block of code once, and then repeats the loop as long as a specified condition is true • for - loops through a block of code a specified number of times • foreach - loops through a block of code for each element in an array
    28. 28. Loops • for for(intialisation;condition;increment/decrement) { //do this code } • while while ( conditional statement is true ) { //do this code; } • do While do {….} while(conditional statement is true); a do-while loop first do's and secondly checks the while condition! • foreach $colors = array("red", "green", "blue", "yellow"); foreach ($colors as $value) { echo "$value <br>"; }
    29. 29. Operators Operators are used to operate on values. There are four classifications of operators:  Arithmetic  Assignment  Comparison  Logical
    30. 30. PHP Operators
    31. 31. PHP Operators
    32. 32. PHP Operators
    33. 33. PHP Operators
    34. 34. Functions and Parameters • PHP functions need to be defined with key word function • It can have zero or more values (parameters) • Functions may or may not return values • If a function need to return value, the last statement of the function should be return – return value;
    35. 35. Functions • Parameter less function <?php function sayHi() { echo “hi”; } ?> This can be called as <?php sayHi(); ?> in the program
    36. 36. Functions • Parameterized function <?php function greet($name) { echo “Hello “ . $name; } ?> This can be called <?php greet(‘Sachin’);?> This gives an output Hello Ram
    37. 37. Functions • Function returning value <?php function add($a,$b) { return ($a + $b); } ?> When called like <?php echo add(1,2);?> we will get an output 3 in the browser.
    38. 38. Example The following example shows how to display content according to the day of the week. 0 (for Sunday) through 6 (for Saturday) <?php $today_dayofweek = date (“w”); if ($today_dayofweek == 0) { echo “enjoy….. today is Sunday !”; } else { echo “Go to Work…today is not Sunday.”; } ?>
    39. 39. Complete Example • Step 1: Universal header and footer in a single file • Create a file called header.php. This file will have all of the header HTML code. Remember to remove the closing </BODY> and </HTML> tags. <html><head> <title>Brainware PHP Workshop</title> <link rel="stylesheet" type="text/css“ href=“mycssfile.css"> </head> <body> <table width=80% border=0> <tr><td> <div align=center> Welcome to BRAINWARE </div> </td></tr> </table>
    40. 40. Complete Example • Step 2: Universal header and footer in a single file • Next, create a file called footer.php. This file will have all of the footer HTML code <table width=80% border=0> <tr><td> <div align=center> Brainware Baguiati Campus<br/> <a href=mailto:info@abc.com>Send Us Email</a> </div> </td></tr> </table> </body> </html>
    41. 41. Complete Example • • Step 3: Universal header and footer in a single file This is the basic template that you will use on all of the pages. Make sure you name the files with a .php extension so that the server will process the PHP code. In this example, we assume the header and footer files are located in the same directory. <?php // header include("header.php"); ?> Insert content here! <?php // footer include("footer.php"); ?>
    42. 42. Example ( Benefits ) Any changes to header or footer only require editing of a single file. These changes will take effect in all the pages where header or footer are included. This reduces the amount of work necessary for site maintenance and redesign. Helps separate the content and design for easier maintenance Header Page 1 Content Page 2 Content Page 3 Content Footer Page 4 Content Page 5 Content
    43. 43. PHP Forms - $_GET Function  The built-in $_GET function is used to collect values from a form sent with method=“GET” <form method= "get" action="action.php"> ... <input ……. </form>  GET is better for non-secure data, like query strings in Google  Information sent from a form with the GET method is visible to everyone all variable names and values are displayed in the URL action.php?name=rahul&age=23&qual=btech This method should not be used when sending passwords or other sensitive information!
    44. 44. PHP Forms - $_POST Function • The built-in $_POST function is used to collect values from a form sent with method=“POST". <form method="post" action=“action.php"> ... <input ……. </form> • Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send. • Note: However, there is an 8 Mb max size for the POST method, by default (can be changed by setting the post_max_size in the php.ini file).
    45. 45. PHP Database Handling • PHP can connect to – MySQL – Access and other databases like Oracle, postgre sql, SQL Server etc • There are separate methods available for connecting to the databases.
    46. 46. What is MySQL • MySQL is a database system used on the web that runs on a server • MySQL is ideal for both small and large applications • MySQL is very fast, reliable, and easy to use • MySQL supports standard SQL • MySQL compiles on a number of platforms • MySQL is free to download and use • MySQL is developed, distributed, and supported by Oracle Corporation
    47. 47. Companies using MySQL
    48. 48. MySQL Connection • mysql_connect(dbserver,userid,password) is used for connecting to MySQL dbserver using a userid and password • $con = mysql_connect(‘localhost’,’root’,’123456’); This gets a connection to the localhost mysql server using the credentials root and 123456 If the mysql server cannot be connected, it will throw an error stating the problem.
    49. 49. MySQL Select DB • mysql_select_db(database,connection) Parameter Description database Required. Specifies the database to use. connection Optional. Specifies the MySQL connection. • mysql_select_db(“students”,$con); – This will select the database students under the server localhost – If unable to select the database, an error will be thrown
    50. 50. MySQL Execute Query mysql_query(sql query, connection); This will execute the sql statement on the database and store the result in a variable. Parameter Description database Required. Specifies the SQL query to run. connection Optional. Specifies the MySQL connection. Example: $rs = mysql_query(“select * from students”, $con); $row = mysql_fetch_array($rs); – – – – This will fetch a row from the table and store in $row Data Values can be accessed like - $row[“age”] returns value of column age from the database in the fetched row. $agevar = $row[“age”]
    51. 51. Our Task
    52. 52. Registration and Login • We will develop a registration and login system using PHP and MySQL • We will need two forms, php scripts and a database • Database - name “pailan” • Table – name “mst_facehook” • Two pages – “registration.html” & “login.html” • PHP Script – “registration.php” & “login.php” • That’s it……… Lets start……
    53. 53. Registration and Login • Database - name “pailan” • Table – name “mst_facehook” Field id email password gender city Type int(10) varchar(200) varchar(100) char(1) varchar(20)
    54. 54. Registration Page
    55. 55. Login Page
    56. 56. SHOUBHIK ROY / SANDEEP BAJORIA email : info@brainware-baguiati.com M : +91 98319 28362 / +91 98309 36993 web : www.brainware-baguiati.com www.facebook.com/Brainware.Kolkata
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×