intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Web engineering: Lecture 23-28 - Majid Mumtaz

Chia sẻ: You You | Ngày: | Loại File: PDF | Số trang:25

45
lượt xem
5
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Upon completion of this lesson, the successful participant will be able to: PHP forms and user input, PHP $_POST method, $_REQUEST with PHP, single page form sumbition, a hyperlinks (Links),... Inviting you to refer lecture for more information.

Chủ đề:
Lưu

Nội dung Text: Web engineering: Lecture 23-28 - Majid Mumtaz

  1. Web Engineering Lecture 23-to-28 MAJID MUMTAZ Department of Computer Science, CIIT Wah 1
  2. PHP forms & user input • The php $_GET & $_POST variable are used to retrieve information from forms, like user input. • PHP $_GET: The $_GET variable is used to collect values from a form with method=”GET”. • The $_GET variable is used to collect values from a form with a method=”GET”. Information sent from a form with the GET method is visible to everyone (It will be displayed in the browser’s address bar) and it has limits on the amount of information to send (max. 2000 characters acc. To W3school website) 2
  3. PHP $_POST Method • The $_POST variable is used to collect values from a form with method=”POST” • The $_POST variable is used to collect values from a form with method=”POST”. Information sent from a form with the POST method is invisible to others and has no limit on the amount of information to send. 3
  4. $_REQUEST with PHP • $_REQUEST variable: variable can be used to get the result from data sent with both the GET and POST methods. i.e. 4
  5. Single Page Form Sumbition • Submitting a single page and retrieve data on same page is a professional way of submitting a form. Let see an example Note: isset() determine if a variable is set and in not null. 5
  6. A Hyperlinks (Links) • A hyperlink or link is a word or group of words or image that you can click on to jump to another document Syntax: Link Text • Getting values in Text box:
  7. Session Variable • Defination: PHP Session variable hold information about one single user, and are available to all pages in one application. • A PHP session solves this problem by allowing to stor user information on the server for latter use. (i.e. User name, shoping items etc). However session information is temporary and will be deleted after the user has left the website. 7
  8. 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 appear before the tag. i.e. 8
  9. Storing a Session variable • The correct way to stor and retrieve session variables is to use the PHP $_SESSION variable. i.e. 9
  10. Destroying a Session • If you wish to delete some session data, you can use the unset() or SESSION_Destroy() functions. The unset() function is used to free the specified session varaiable. i.e. You can also completely destroy the session by calling the session_destroy() function. i.e. Note: Session_destroy() will reset you session and you will lose all your stored session data. 10
  11. PHP cookies • Cookies is a small file that the server embeds on the user’s computer. Each time the same computer request a page with browser it will send the cookies too with PHP, you can both create and retrieve cookie values. Difference betweek Cookies and Session: Session data is stored on the server, while cookie data is stored on the client side. 11
  12. Popular use of cookies • Cookies are – To store username/pwd info so that the user doesn’t have to log in every time they visit the website. (’remember me’ while doing signings) – To simply remember the user’s name – To keep track of a user’s progress during a specific process – To remember a user’s theme 12
  13. Creating cookies • The setcookie() funciton is used to set a cookie. Note: the setcookie() funciton must appear before tag. • Syntax setcookie(name, value, expire, path, domain); • Example In above example we have created a cookie named ”user” and assign the value ”Faraz” to it. We have also specified that the cookie will expire after an hour. 13
  14. PHP programming using Database • What is Data: Raw facts & figures • What is information: Arrangement of data in suitable way. Or Organized data is known as an information. E.g. Example-1 Roll No Name Class Address Ali MBA Lahore 1098 Example-2 Roll No Name Class Address 1098 Ali MBA Lahore 14
  15. What is a Database • Database is a collection of data that is organized so that its contents can easily be accessed, manage and updated. Database are useful when storing infomation categorically. E.g. A company may have a database, Uni. May have large database etc. • What is MySQL? MySQL is a database that defines a structure for storing information. 15
  16. Database (University) • Entity (student, teach, Employees) • Table • Field • Record – Primay Key: a unique value in a table, cann’t be null , can never be duplicate. 16
  17. 1) PHP MySQL Connection • PHP 5 and later can work with a MySQL database using: – MySQLi extension (the "i" stands for improved) – PDO (PHP Data Objects) Should I Use MySQLi or PDO? • If you need a short answer, it would be "Whatever you like". • Both MySQLi and PDO have their advantages: • PDO will work on 12 different database systems, where as MySQLi will only work with MySQL databases. • So, if you have to switch your project to use another database, PDO makes the process easy. You only have to change the connection string and a few queries. With MySQLi, you will need to rewrite the entire code - queries included. • Both are object-oriented, but MySQLi also offers a procedural API. 17
  18. 1) PHP MySQL Connection • Connecting to MySQL database by using PHP 18
  19. 2) PHP MySQL command (Insertion) • The INSERT INTO statement is used to insert new records in a table. There are two method to perform database insertion task. • 1st Method – Syntax: INSERT INTO table_Name VALUES (valu1, value2, ...) • 2nd Method – Syntax: INSERT INTO table_Name(column1, column2,...) VALUES(value1, value2,...) Example: $sql = "insert into students values($r, '$name', '$class')"; 19
  20. 3-4) PHP MySQL Query & closing • To execute query successfully on database the final step is to use mysql_query() function. mysqli_query($con, $sql); • To close database connection the following method should be used Mysqli_close($con); 20
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2