Presentation is loading. Please wait.

Presentation is loading. Please wait.

XAMPP: Cross – Apache, MySQL, Php, Perl + FileZilla, Tomcat NetBeans: IDE PHP Installation.

Similar presentations


Presentation on theme: "XAMPP: Cross – Apache, MySQL, Php, Perl + FileZilla, Tomcat NetBeans: IDE PHP Installation."— Presentation transcript:

1 XAMPP: Cross – Apache, MySQL, Php, Perl + FileZilla, Tomcat NetBeans: IDE PHP Installation

2 PHP - XAMPP

3 PHP – NetBeans IDE

4 Netbeans- default browser

5 Netbeans – Starts a project

6 PHP – Starting a project

7 Netbeans – Setting a project

8 Basic PHP Syntax

9 Comment in Php

10 PHP Variables <?php $txt="Hello World!"; $x=16; echo $txt; ?> --------------- Hello World!

11 PHP Operators ArithmeticAssignmentComparisonLogicalString +== &&. (Append) -+=! =|| *-= ! /*=> %/=> = ++%=< - < =

12 if

13 if

14 switch

15 Numeric Arrays $cars=array("Saab","Volvo","BMW","Toyota"); -------------or $cars[0]="Saab"; $cars[1]="Volvo"; $cars[2]="BMW"; $cars[3]="Toyota"; echo $cars[0]. " and ". $cars[1]. " are Swedish cars.";

16 Associative Arrays ID key => value $ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34); -------------------or----------------- $ages['Peter'] = "32"; $ages['Quagmire'] = "30"; $ages['Joe'] = "34"; echo "Peter is ". $ages['Peter']. " years old."; ---------------------------------- Peter is 32 years old.

17 Multidimensional Arrays $families = array ( "Griffin"=>array ( "Peter", "Lois", "Megan" ), "Quagmire"=>array ( "Glenn" ), "Brown"=>array ( "Cleveland", "Loretta", "Junior" ) ); Array ( [Griffin] => Array ( [0] => Peter [1] => Lois [2] => Megan ) [Quagmire] => Array ( [0] => Glenn ) [Brown] => Array ( [0] => Cleveland [1] => Loretta [2] => Junior ) )

18 Multidimensional Arrays echo "Is ". $families['Griffin'][2]. " a part of the Griffin family?"; ---------------------------------- Is Megan a part of the Griffin family?

19 While Loops "; $i++; } ?> The number is 1 The number is 2 The number is 3 The number is 4 The number is 5

20 Do While Loops "; } while ($i The number is 2 The number is 3 The number is 4 The number is 5 The number is 6

21 For Loops "; } ?> The number is 1 The number is 2 The number is 3 The number is 4 The number is 5

22 Foreach Loops <?php $x=array("one","two","three"); foreach ($x as $value) { echo $value. " "; } ?> one two three

23 Create a PHP Function My name is Kai Jim Refsnes

24 Create a PHP Function "; } echo "My name is "; writeName("Kai Jim"); echo "My sister's name is "; writeName("Hege"); echo "My brother's name is "; writeName("Stale"); ?> My name is Kai Jim Refsnes. My sister's name is Hege Refsnes. My brother's name is Stale Refsnes.

25 Create a PHP Function "; } echo "My name is "; writeName("Kai Jim","."); echo "My sister's name is "; writeName("Hege","!"); echo "My brother's name is "; writeName("Ståle","?"); ?> My name is Kai Jim Refsnes. My sister's name is Hege Refsnes! My brother's name is Ståle Refsnes?i

26 Create a PHP Function 1 + 16 = 17

27 $_GET variable Name: Age: ----------------------------- http://localhost/welcome.php?fname=Peter&age=37 ----------------------------- Welcome. You are years old! When using method="get" in HTML forms, all variable names and values are displayed in the URL.

28 $_POST variable Name: Age: ------------------------------------ Welcome ! You are years old. Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send. However, because the variables are not displayed in the URL, it is not possible to bookmark the page.

29 $_REQUEST Variable Welcome ! You are years old. ---------- The predefined $_REQUEST variable contains the contents of both $_GET, $_POST, and $_COOKIE. The $_REQUEST variable can be used to collect form data sent with both the GET and POST methods.

30 PHP Date() Function date(format [, timestamp]) "; echo date("Y-m-d"); ?> 2011/11/17 2011-11-17

31 PHP Date() Function mktime(hour,minute,second,month,day,year,is_dst) Tomorrow is 2011/11/18

32 PHP include() Function Welcome to my home page! Some text.

33 PHP include() Function menu.php Home Tutorials References Examples About Us Contact Us Welcome to my home page. Some text.

34 PHP File Handling Reading a File Line by Line "; } fclose($file); ?>

35 PHP File Handling Reading a File Character by Character

36 PHP File Upload Create an Upload-File Form Filename:

37 Create The Upload Script upload_file.php 0) { echo "Error: ". $_FILES["file"]["error"]. " "; } else { echo "Upload: ". $_FILES["file"]["name"]. " "; echo "Type: ". $_FILES["file"]["type"]. " "; echo "Size: ". ($_FILES["file"]["size"] / 1024). " Kb "; echo "Stored in: ". $_FILES["file"]["tmp_name"]; } ?>

38 Save uploaded File upload_file.php

39 Create a Cookie setcookie(name, value, expire, path, domain); 60 sec * 60 min * 24 hours * 30 days

40 Retrive a Cookie "; else echo "Welcome guest! "; ?>

41 Delete a Cookie

42 PHP Session Variables Starting a PHP Session Before you can store user information in your PHP session, you must first start up the session. Note: The session_start() function must apear BEFORE the tag:

43 PHP Session Variables

44 PHP Session Variables

45 PHP Destroying a Session Free a session variable

46 PHP mail() Function

47 PHP mail() Function Email: Subject: Message: "; } ?>

48 Error Handling

49 Error Handling Error: [$errno] $errstr "; echo "Ending Script"; die(); } //set error handler set_error_handler("customError",E_USER_WARNING); //trigger error $test=2; if ($test>1) { trigger_error("Value must be 1 or below",E_USER_WARNING); } ?>

50 Error Handling 1) { throw new Exception("Value must be 1 or below"); } return true; } //trigger exception in a "try" block try { checkNum(2); //If the exception is thrown, this text will not be shown echo 'If you see this, the number is 1 or below'; } //catch exception catch(Exception $e) { echo 'Message: '.$e->getMessage(); } ?> Message: Value must be 1 or below

51 Filter & Sanitize Check if the "url" input of the "POST" type exists If the input variable exists, sanitize (take away invalid characters) and store it in the $url variable "http://www.csuååohioøø.edu/ http://www.csuohio.edu/

52 MySQL Workbench http://wb.mysql.com/

53 Connect / Close a DB mysql_connect(servername,username,password);

54 Create a Database if (mysql_query("CREATE DATABASE my_db",$con)) { echo "Database created"; } else { echo "Error creating database: ". mysql_error(); }

55 Create a Table // Create table mysql_select_db("my_db", $con); $sql = "CREATE TABLE Persons ( FirstName varchar(15), LastName varchar(15), Age int )"; // Execute query mysql_query($sql,$con);

56 Create a Table mysql_select_db("my_db", $con); $sql = "CREATE TABLE Persons ( personID int NOT NULL AUTO_INCREMENT, PRIMARY KEY(personID), FirstName varchar(15), LastName varchar(15), Age int )"; mysql_query($sql,$con);

57 Insert a Table mysql_select_db("my_db", $con); mysql_query("INSERT INTO Persons (FirstName, LastName, Age) VALUES ('Peter', 'Griffin', '35')"); mysql_query("INSERT INTO Persons (FirstName, LastName, Age) VALUES ('Glenn', 'Quagmire', '33')");

58 Insert Data From a Form Into a Database Firstname: Lastname: Age:

59 Insert Data From a Form Into a Database mysql_select_db("my_db", $con); $sql="INSERT INTO Persons (FirstName, LastName, Age) VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[age]')"; if (!mysql_query($sql,$con)) { die('Error: '. mysql_error()); } echo "1 record added";

60 Select Data From a Database Table "; } mysql_close($con); ?>

61 Display the Result in an HTML Table Firstname Lastname "; while($row = mysql_fetch_array($result)) { echo " "; echo " ". $row['FirstName']. " "; echo " ". $row['LastName']. " "; echo " "; } echo " "; mysql_close($con); ?>

62 The WHERE clause "; } ?>

63 Update Data In a Database

64 Delete Data In a Database


Download ppt "XAMPP: Cross – Apache, MySQL, Php, Perl + FileZilla, Tomcat NetBeans: IDE PHP Installation."

Similar presentations


Ads by Google