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 modul-3

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 modul-3 (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

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Recently uploaded (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Php modul-3

  • 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