SlideShare a Scribd company logo
1 of 24
PHP TUTORIAL
PHP and Database
What is Database?
● A database is an organized collection of
data.
● The data collection are typically organized
to model relevant aspects of reality in a
way that supports processes requiring this
information
What is Database Management
System?
● Database management systems (DBMSs) are
specially designed applications that interact
with the user, other applications, and the
database itself to capture and analyze data.
● A general-purpose database management
system (DBMS) is a software system designed
to allow the definition, creation, querying,
update, and administration of databases.
Why use database?
● Databases are most useful when it comes
to storing information that fits into logical
categories.
● Example: store employees record
– Supervisors table, managers tables, suppliers
table, etc.
Why MySQL?
● The most popular database system used with PHP.
● PHP combined with MySQL are cross-platform (you
can develop in Windows and serve on a Unix platform)
● Most web hosts do not allow you to create a database
directly through a PHP script.
● Instead they require that you use the PHP/MySQL
administration tools on the web host control panel to
create these databases
What is “Queries”
● A query is a question or a request.
● We can query a database for specific
information and have a recordset returned
● Example:
– SELECT * FROM customers;
How to learn SQL
● Remember this:
– SQL language is not complicated
● There are many keywords in MySQL, and a
good programming habit when using ANY of
these words is to capitalize them.
● This helps draw them out from the rest of the
code and makes them much easier to read.
● Example:
– SELECT * FROM example
SQL Basic Command
● Create Database
– CREATE DATABASE <database_name>
● Use Database
– Use <database_name>
● Create Table
– CREATE TABLE <table_name> (col1 type1, col2 type2, … , colx
typex)
● Example
– CREATE DATABASE exercise;
– Use exercise;
– CREATE TABLE student (name varchar(30), age INT);
SQL Basic Command
● Insert data to table
– INSERT INTO <table_name> (col1,col2, … , colx)
VALUES (val1, val2, … , valx);
– Example:
● INSERT INTO student VALUES ('William',27);
● Query data from table
– SELECT <colx| *> FROM <table_name> WHERE
<expression>
– Example:
● SELECT name FROM student WHERE age>20;
SQL Basic Command
● Edit data
– UPDATE <table_name> SET <colx=valx> WHERE
<expression>
● Delete data
– DELETE FROM <table_name> WHERE <expression>
● Example
– UPDATE student SET age=30 WHERE
name='William';
– DELETE FROM student WHERE name='William';
PHP Form Handling
● Use $_GET or $_POST to handle the data from the form
● Example (form_get.html)
<html>
<body>
<form action="helloget.php" method="get">
Name: <input type="text" name="name"><br>
<input type="submit">
</form>
</body>
</html>
PHP Form Handling
● Helloget.php
<html>
<body>
Welcome <?php echo $_GET["name"]; ?>
</body>
</html>
PHP Form Handling
● (form_post.html)
<html>
<body>
<form action="hellopost.php" method="post">
Name: <input type="text" name="name"><br>
<input type="submit">
</form>
</body>
</html>
PHP Form Handling
● Hellopost.php
<html>
<body>
Welcome <?php echo $_POST["name"]; ?>
</body>
</html>
PHP Form Handling
● GET vs. POST
– $_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.
PHP Form Handling
● When we use GET method?
– Remember this : Information sent from a form
with the GET method is visible to everyone
(in address bar).
– GET has limits on the amount of information
to send (only 2000 character).
– ONLY USED for sending non-sensitive data.
– Never use GET to send sensitive informations
such as username or password
PHP Form Handling
● When we use POST method?
– Remember this : Information sent from a form
with the POST method is invisible to others.
– POST has no limits on the amount of
information to send.
– Supports advanced functionality such as multi-
part binary input while uploading files to
server.
PHP & MySQL
● Open connection to MySQL
– mysqli_connect(host, username, password,
database_name)
– Example
$con=mysqli_connect(“localhost”,”root”,”1234”,”exercis
e”);
● Check connection
if (mysqli_connect_errno($con))
echo "Failed to connect to MySQL: " .
mysqli_connect_error();
PHP and MySQL
● Close connection
– mysqli_close(connection_variable)
● Example
– mysqli_close($con);
PHP and MySQL
● Send query to MySQL
– mysqli_query(<query>,<connection_variable>
);
● Example:
$sql=”INSERT INTO student
VALUES('John',33)”;
mysqli_query($sql,$con);
PHP and MySQL
● Retrieve result of query
$sql=”SELECT * FROM student”;
$result=mysqli_query($sql,$con);
While ($row = mysqli_fetch_array($result)) {
echo $row['name'] . “ “ . $row['age'] . “<br>”;
}
excercise
● A. Database
– Use database exercise
– Create a course table which have structure like this:
● id_course – varchar
● name_course – varchar
● Credit – int
– Create a student table which have structure like this:
● id_student – varchar
● Firstname – varchar
● Lastname - varchar
– Insert 10 data into table course and student
excercise
● B. PHP and MySQL
– Create a web application with php to handles
● The input for table course and student
● List all data for table course and student
● Search data for table course and student
Home Works
● Create a web applications with PHP to
handle the update and delete proses for
table course and student

More Related Content

Viewers also liked

Viewers also liked (7)

Θέμα Δράσης: «Παγκόσμια Ημέρα Ατόμων με Ειδικές Ανάγκες»
Θέμα Δράσης: «Παγκόσμια Ημέρα Ατόμων με Ειδικές Ανάγκες»Θέμα Δράσης: «Παγκόσμια Ημέρα Ατόμων με Ειδικές Ανάγκες»
Θέμα Δράσης: «Παγκόσμια Ημέρα Ατόμων με Ειδικές Ανάγκες»
 
Php modul-1
Php modul-1Php modul-1
Php modul-1
 
United kingdom
United kingdomUnited kingdom
United kingdom
 
Παγκόσμια ημέρα υγροτόπων
Παγκόσμια ημέρα υγροτόπωνΠαγκόσμια ημέρα υγροτόπων
Παγκόσμια ημέρα υγροτόπων
 
United kingdom
United kingdomUnited kingdom
United kingdom
 
Php modul-2
Php modul-2Php modul-2
Php modul-2
 
Aνακύκλωση και παιχνίδια
Aνακύκλωση και παιχνίδια Aνακύκλωση και παιχνίδια
Aνακύκλωση και παιχνίδια
 

Similar to PHP Tutorial Covers Databases, SQL, and Integrating PHP with MySQL

PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slidesmetsarin
 
BITS: Introduction to MySQL - Introduction and Installation
BITS: Introduction to MySQL - Introduction and InstallationBITS: Introduction to MySQL - Introduction and Installation
BITS: Introduction to MySQL - Introduction and InstallationBITS
 
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering College
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering CollegeDatabase Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering College
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering CollegeDhivyaa C.R
 
Introduction to SQLite in Adobe AIR
Introduction to SQLite in Adobe AIRIntroduction to SQLite in Adobe AIR
Introduction to SQLite in Adobe AIRPeter Elst
 
Top 10 Mistakes When Migrating From Oracle to PostgreSQL
Top 10 Mistakes When Migrating From Oracle to PostgreSQLTop 10 Mistakes When Migrating From Oracle to PostgreSQL
Top 10 Mistakes When Migrating From Oracle to PostgreSQLJim Mlodgenski
 
Oracle postgre sql-mirgration-top-10-mistakes
Oracle postgre sql-mirgration-top-10-mistakesOracle postgre sql-mirgration-top-10-mistakes
Oracle postgre sql-mirgration-top-10-mistakesJim Mlodgenski
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2ADARSH BHATT
 
A Brief Introduction in SQL Injection
A Brief Introduction in SQL InjectionA Brief Introduction in SQL Injection
A Brief Introduction in SQL InjectionSina Manavi
 
PHP and MySQL.pptx
PHP and MySQL.pptxPHP and MySQL.pptx
PHP and MySQL.pptxnatesanp1234
 
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQLTen Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQLanandology
 
DIWE - Working with MySQL Databases
DIWE - Working with MySQL DatabasesDIWE - Working with MySQL Databases
DIWE - Working with MySQL DatabasesRasan Samarasinghe
 

Similar to PHP Tutorial Covers Databases, SQL, and Integrating PHP with MySQL (20)

PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slides
 
BITS: Introduction to MySQL - Introduction and Installation
BITS: Introduction to MySQL - Introduction and InstallationBITS: Introduction to MySQL - Introduction and Installation
BITS: Introduction to MySQL - Introduction and Installation
 
My sql1
My sql1My sql1
My sql1
 
UNIT V (5).pptx
UNIT V (5).pptxUNIT V (5).pptx
UNIT V (5).pptx
 
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering College
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering CollegeDatabase Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering College
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering College
 
Introduction to SQLite in Adobe AIR
Introduction to SQLite in Adobe AIRIntroduction to SQLite in Adobe AIR
Introduction to SQLite in Adobe AIR
 
Top 10 Mistakes When Migrating From Oracle to PostgreSQL
Top 10 Mistakes When Migrating From Oracle to PostgreSQLTop 10 Mistakes When Migrating From Oracle to PostgreSQL
Top 10 Mistakes When Migrating From Oracle to PostgreSQL
 
Oracle postgre sql-mirgration-top-10-mistakes
Oracle postgre sql-mirgration-top-10-mistakesOracle postgre sql-mirgration-top-10-mistakes
Oracle postgre sql-mirgration-top-10-mistakes
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 
Php summary
Php summaryPhp summary
Php summary
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
 
Data base.ppt
Data base.pptData base.ppt
Data base.ppt
 
A Brief Introduction in SQL Injection
A Brief Introduction in SQL InjectionA Brief Introduction in SQL Injection
A Brief Introduction in SQL Injection
 
MYSQL-Database
MYSQL-DatabaseMYSQL-Database
MYSQL-Database
 
PHP and MySQL.pptx
PHP and MySQL.pptxPHP and MySQL.pptx
PHP and MySQL.pptx
 
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQLTen Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
 
SQL - RDBMS Concepts
SQL - RDBMS ConceptsSQL - RDBMS Concepts
SQL - RDBMS Concepts
 
MySQL for beginners
MySQL for beginnersMySQL for beginners
MySQL for beginners
 
DIWE - Working with MySQL Databases
DIWE - Working with MySQL DatabasesDIWE - Working with MySQL Databases
DIWE - Working with MySQL Databases
 
Database.pdf
Database.pdfDatabase.pdf
Database.pdf
 

Recently uploaded

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Recently uploaded (20)

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

PHP Tutorial Covers Databases, SQL, and Integrating PHP with MySQL

  • 2. What is Database? ● A database is an organized collection of data. ● The data collection are typically organized to model relevant aspects of reality in a way that supports processes requiring this information
  • 3. What is Database Management System? ● Database management systems (DBMSs) are specially designed applications that interact with the user, other applications, and the database itself to capture and analyze data. ● A general-purpose database management system (DBMS) is a software system designed to allow the definition, creation, querying, update, and administration of databases.
  • 4. Why use database? ● Databases are most useful when it comes to storing information that fits into logical categories. ● Example: store employees record – Supervisors table, managers tables, suppliers table, etc.
  • 5. Why MySQL? ● The most popular database system used with PHP. ● PHP combined with MySQL are cross-platform (you can develop in Windows and serve on a Unix platform) ● Most web hosts do not allow you to create a database directly through a PHP script. ● Instead they require that you use the PHP/MySQL administration tools on the web host control panel to create these databases
  • 6. What is “Queries” ● A query is a question or a request. ● We can query a database for specific information and have a recordset returned ● Example: – SELECT * FROM customers;
  • 7. How to learn SQL ● Remember this: – SQL language is not complicated ● There are many keywords in MySQL, and a good programming habit when using ANY of these words is to capitalize them. ● This helps draw them out from the rest of the code and makes them much easier to read. ● Example: – SELECT * FROM example
  • 8. SQL Basic Command ● Create Database – CREATE DATABASE <database_name> ● Use Database – Use <database_name> ● Create Table – CREATE TABLE <table_name> (col1 type1, col2 type2, … , colx typex) ● Example – CREATE DATABASE exercise; – Use exercise; – CREATE TABLE student (name varchar(30), age INT);
  • 9. SQL Basic Command ● Insert data to table – INSERT INTO <table_name> (col1,col2, … , colx) VALUES (val1, val2, … , valx); – Example: ● INSERT INTO student VALUES ('William',27); ● Query data from table – SELECT <colx| *> FROM <table_name> WHERE <expression> – Example: ● SELECT name FROM student WHERE age>20;
  • 10. SQL Basic Command ● Edit data – UPDATE <table_name> SET <colx=valx> WHERE <expression> ● Delete data – DELETE FROM <table_name> WHERE <expression> ● Example – UPDATE student SET age=30 WHERE name='William'; – DELETE FROM student WHERE name='William';
  • 11. PHP Form Handling ● Use $_GET or $_POST to handle the data from the form ● Example (form_get.html) <html> <body> <form action="helloget.php" method="get"> Name: <input type="text" name="name"><br> <input type="submit"> </form> </body> </html>
  • 12. PHP Form Handling ● Helloget.php <html> <body> Welcome <?php echo $_GET["name"]; ?> </body> </html>
  • 13. PHP Form Handling ● (form_post.html) <html> <body> <form action="hellopost.php" method="post"> Name: <input type="text" name="name"><br> <input type="submit"> </form> </body> </html>
  • 14. PHP Form Handling ● Hellopost.php <html> <body> Welcome <?php echo $_POST["name"]; ?> </body> </html>
  • 15. PHP Form Handling ● GET vs. POST – $_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.
  • 16. PHP Form Handling ● When we use GET method? – Remember this : Information sent from a form with the GET method is visible to everyone (in address bar). – GET has limits on the amount of information to send (only 2000 character). – ONLY USED for sending non-sensitive data. – Never use GET to send sensitive informations such as username or password
  • 17. PHP Form Handling ● When we use POST method? – Remember this : Information sent from a form with the POST method is invisible to others. – POST has no limits on the amount of information to send. – Supports advanced functionality such as multi- part binary input while uploading files to server.
  • 18. PHP & MySQL ● Open connection to MySQL – mysqli_connect(host, username, password, database_name) – Example $con=mysqli_connect(“localhost”,”root”,”1234”,”exercis e”); ● Check connection if (mysqli_connect_errno($con)) echo "Failed to connect to MySQL: " . mysqli_connect_error();
  • 19. PHP and MySQL ● Close connection – mysqli_close(connection_variable) ● Example – mysqli_close($con);
  • 20. PHP and MySQL ● Send query to MySQL – mysqli_query(<query>,<connection_variable> ); ● Example: $sql=”INSERT INTO student VALUES('John',33)”; mysqli_query($sql,$con);
  • 21. PHP and MySQL ● Retrieve result of query $sql=”SELECT * FROM student”; $result=mysqli_query($sql,$con); While ($row = mysqli_fetch_array($result)) { echo $row['name'] . “ “ . $row['age'] . “<br>”; }
  • 22. excercise ● A. Database – Use database exercise – Create a course table which have structure like this: ● id_course – varchar ● name_course – varchar ● Credit – int – Create a student table which have structure like this: ● id_student – varchar ● Firstname – varchar ● Lastname - varchar – Insert 10 data into table course and student
  • 23. excercise ● B. PHP and MySQL – Create a web application with php to handles ● The input for table course and student ● List all data for table course and student ● Search data for table course and student
  • 24. Home Works ● Create a web applications with PHP to handle the update and delete proses for table course and student