Presentation is loading. Please wait.

Presentation is loading. Please wait.

1Computer Sciences Department Princess Nourah bint Abdulrahman University.

Similar presentations


Presentation on theme: "1Computer Sciences Department Princess Nourah bint Abdulrahman University."— Presentation transcript:

1 1Computer Sciences Department Princess Nourah bint Abdulrahman University

2 And use http://www.w3schools.com/http://www.w3schools.com/

3 PHP Part 3

4  Creating a new MySQL Database using………  Create & Check connection with Database that has been created.  Creating a new table  Form Handling  GET vs. POST methods  Insert, select, delete, update data Objectives Computer Sciences Department4

5 5 Creating a new MySQL Database

6  After WAMP server has started, you will see the WAMP icon as shown below in the notification area at the bottom-right side of the desktop.  If the icon is green as shown above, all services like Apache, MySQL etc. are running. If the icon is not green, left-click on it. You will see the WAMP administrator panel as shown below. Click on “Start All Services”. Computer Sciences Department6 Step 1

7  Click on “phpMyAdmin” under the “Tools” section. Log in with Username and Password for MySQL. Generally, the Username is "root" with no Password required for the Super user of MySQL Computer Sciences Department7 Step 2

8 Computer Sciences Department8 Step 3 “create a new Database” Note: Don't use a dot( “.”) in the database name

9 Computer Sciences Department9 Step 4 “create a new Table” 1 2 3 4

10 Computer Sciences Department10 Step 5 “Create new field”

11  Insert, delete, or modify ……etc. date Computer Sciences Department11 Step 6

12 Computer Sciences Department12 Create a form “example”

13  When the user fills out the form …….and clicks the submit button, the form data is sent for processing to a PHP file named “?????????.php".  The form data is sent with the HTTP POST method. Computer Sciences Department13 PHP 5 Form Handling

14   ID:  Name:  Date:  Computer Sciences Department14 Step 7 “create a form”

15  Both GET and POST create an array (e.g. array( key => value, key2 => value2, key3 => value3,...)). This array holds key/value pairs, where keys are the names of the form controls and values are the input data from the user.  $_GET is an array of variables passed to the current script via the URL parameters.  $_POST is an array of variables passed to the current script via the HTTP POST method Computer Sciences Department15 GET vs. POST

16  Information sent from a form with the GET method is visible to everyone (all variable names and values are displayed in the URL). GET also has limits on the amount of information to send. The limitation is about 2000 characters. However, because the variables are displayed in the URL, it is possible to bookmark the page. This can be useful in some cases.  GET may be used for sending non-sensitive data.  Note: GET should NEVER be used for sending passwords or other sensitive information! Computer Sciences Department16 When to use GET?

17  $user = 'root';  $pass = '';  $db = 'db_test';  $hostname = 'localhost';  // Create connection  $con=mysqli_connect($hostname,$user, $pass, $db);  // Check connection  if (mysqli_connect_errno())  {  echo "Failed to connect to DataBase: ". mysqli_connect_error();  } Computer Sciences Department17 Step 8 “Create & Check connection with Database”

18  Information sent from a form with the POST method is invisible to others (all names/values are embedded within the body of the HTTP request) and has no limits on the amount of information to send.  Moreover POST supports advanced functionality such as support for multi-part binary input while uploading files to server.  However, because the variables are not displayed in the URL, it is not possible to bookmark the page. Computer Sciences Department18 When to use POST?

19  Explanation Explanation Computer Sciences Department19 PHP 5 Form Validation

20  When some fields cannot be empty and must be filled out in the HTML form.  if (empty($_POST["name"])) { $nameErr = "Name is required"; } else { $name = test_input($_POST["name"]); }  Example Example Computer Sciences Department20 PHP 5 Forms - Required Fields

21 Computer Sciences Department21 Insert, select, delete, update data

22 Computer Sciences Department22

23 Computer Sciences Department23

24  The SELECT statement is used to select data from one or more tables  SELECT column_name(s) FROM table_name  or we can use the * character to select ALL columns from a table:  SELECT * FROM table_name Computer Sciences Department24 PHP Select Data From MySQL

25 Computer Sciences Department25

26  The DELETE statement is used to delete records from a table  DELETE FROM table_name WHERE some_column = some_value Computer Sciences Department26 PHP Delete Data From MySQL

27 Computer Sciences Department27

28  The UPDATE statement is used to update existing records in a table  UPDATE table_name SET column1=value, column2=value2,... WHERE some_column=some_value Computer Sciences Department28 PHP Update Data in MySQL

29 Computer Sciences Department29


Download ppt "1Computer Sciences Department Princess Nourah bint Abdulrahman University."

Similar presentations


Ads by Google