SlideShare uma empresa Scribd logo
1 de 11
CN5109
WEB APPLICATION
DEVELOPMENT
Chapter 8
MySQLi PHP Syntax – Working with Data
MySQLi Insert Data
• To insert data into MySQLi table, you would need to use
SQL INSERT INTO command.
• You can use INSERT INTO command into PHP function
mysqli_query() to insert data into a MySQLi table.
MySQLi Insert Data
• Example:
/* HTML FORM*/
<form action = “ " method = "post">
<label>Full Name :</label>
<input type = "text" name = “fname" /> <br /> <br />
<input type = "submit" value ="Submit" name = "submit"/> <br />
</form>
MySQLi Insert Data
• Example:
/* PHP FILE */
<?php
// Connection to Database
// Select Database
$sql = "INSERT INTO table1(fname)VALUES ('".$_POST[“fname"]."')";
if (mysqli_query($conn, $sql))
{
echo "New record created successfully";
}
else
{
echo "Error: " . $sql . “ " . mysqli_error($conn);
}
mysqli_close($conn);
?>
MySQLi Query Data
• The SQL SELECT command is used to fetch data from
MySQLi database.
• You can use same SQL SELECT command into PHP
function mysqli_query().
• This function is used to execute SQL command and later
another PHP function mysqli_fetch_assoc() can be used
to fetch all the selected data.
• This function returns row as an associative array, a
numeric array, or both.
• This function returns FALSE if there are no more rows.
MySQLi Query Data
• Example:
<?php
// Connection to Database
// Select Database
$sql = 'SELECT fname FROM table1';
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result))
{
echo "Name: " . $row["name"]. "<br>";
}
}
else
{
echo "0 result";
}
mysqli_close($conn);
?>
MySQLi Query Data
• We have seen SQL SELECT command to fetch data from
MySQLi table.
• We can use a conditional clause called WHERE clause to
filter out results.
• Using WHERE clause, we can specify a selection criteria
to select required records from a table.
• The WHERE clause works like an if condition in any
programming language. This clause is used to compare
given value with the field value available in MySQLi table.
• If given value from outside is equal to the available field
value in MySQLi table, then it returns that row.
• You can use same SQL SELECT command with WHERE
CLAUSE into PHP function mysqli_query().
MySQLi Query Data
• Example:
<?php
// Connection to Database
// Select Database
$sql = 'SELECT fname FROM table1 WHERE fname=“ahmad”';
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result))
{
echo "Name: " . $row["name"]. "<br>";
}
}
else
{
echo "0 result";
}
mysqli_close($conn);
?>
MySQLi UPDATE Data
• There may be a requirement where existing data in a
MySQLi table needs to be modified.
• You can do so by using SQL UPDATE command.
• This will modify any field value of any MySQLi table.
• You can update one or more field altogether.
• You can specify any condition using WHERE clause.
• You can update values in a single table at a time.
• You can use SQL UPDATE command with or without
WHERE CLAUSE into PHP function mysqli_query().
MySQLi UPDATE Data
• Example:
<?php
// Connection to Database
// Select Database
$sql = ' UPDATE table1 SET fname="althamas" WHERE name="ram"';
if (mysqli_query($conn, $sql))
{
echo "Record updated successfully";
}
else
{
echo "Error updating record: " . mysqli_error($conn);
}
mysqli_close($conn);
?>
MySQLi DELETE Data
• If you want to delete a record from any MySQLi table,
then you can use SQL command DELETE FROM.
• If WHERE clause is not specified, then all the records will
be deleted from the given MySQLi table.
• You can specify any condition using WHERE clause.
• You can delete records in a single table at a time.
• You can use SQL DELETE command with or without
WHERE CLAUSE into PHP function mysqli_query().

Mais conteúdo relacionado

Mais procurados

Using php with my sql
Using php with my sqlUsing php with my sql
Using php with my sql
salissal
 

Mais procurados (20)

SPFx working with SharePoint data
SPFx working with SharePoint dataSPFx working with SharePoint data
SPFx working with SharePoint data
 
SPFx: Working with SharePoint Content
SPFx: Working with SharePoint ContentSPFx: Working with SharePoint Content
SPFx: Working with SharePoint Content
 
Php Mysql
Php Mysql Php Mysql
Php Mysql
 
PHP and Mysql
PHP and MysqlPHP and Mysql
PHP and Mysql
 
MySQLi
MySQLiMySQLi
MySQLi
 
Mysql & Php
Mysql & PhpMysql & Php
Mysql & Php
 
PDO Basics - PHPMelb 2014
PDO Basics - PHPMelb 2014PDO Basics - PHPMelb 2014
PDO Basics - PHPMelb 2014
 
Thymeleaf Introduction
Thymeleaf IntroductionThymeleaf Introduction
Thymeleaf Introduction
 
lab56_db
lab56_dblab56_db
lab56_db
 
Php Training Workshop by Vtips
Php Training Workshop by VtipsPhp Training Workshop by Vtips
Php Training Workshop by Vtips
 
Lab5 sub query
Lab5   sub queryLab5   sub query
Lab5 sub query
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For Beginners
 
Php classes in mumbai
Php classes in mumbaiPhp classes in mumbai
Php classes in mumbai
 
Request dispacther interface ppt
Request dispacther interface pptRequest dispacther interface ppt
Request dispacther interface ppt
 
Php workshop L04 database
Php workshop L04 databasePhp workshop L04 database
Php workshop L04 database
 
Using php with my sql
Using php with my sqlUsing php with my sql
Using php with my sql
 
Message enricher in mule
Message enricher in muleMessage enricher in mule
Message enricher in mule
 
Php workshop L03 superglobals
Php workshop L03 superglobalsPhp workshop L03 superglobals
Php workshop L03 superglobals
 
Databases and MySQL
Databases and MySQLDatabases and MySQL
Databases and MySQL
 
Working with WP_Query in WordPress
Working with WP_Query in WordPressWorking with WP_Query in WordPress
Working with WP_Query in WordPress
 

Semelhante a Web Application Development using PHP Chapter 8

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
Dhivyaa C.R
 
PHP DATABASE MANAGEMENT.pptx
PHP DATABASE MANAGEMENT.pptxPHP DATABASE MANAGEMENT.pptx
PHP DATABASE MANAGEMENT.pptx
CynthiaKendi1
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
ADARSH BHATT
 
Database presentation
Database presentationDatabase presentation
Database presentation
webhostingguy
 
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docxModule 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
moirarandell
 
9780538745840 ppt ch08
9780538745840 ppt ch089780538745840 ppt ch08
9780538745840 ppt ch08
Terry Yoast
 
PHP 5 + MySQL 5 = A Perfect 10
PHP 5 + MySQL 5 = A Perfect 10PHP 5 + MySQL 5 = A Perfect 10
PHP 5 + MySQL 5 = A Perfect 10
Adam Trachtenberg
 

Semelhante a Web Application Development using PHP Chapter 8 (20)

PHP with MySQL
PHP with MySQLPHP with MySQL
PHP with MySQL
 
4.3 MySQL + PHP
4.3 MySQL + PHP4.3 MySQL + PHP
4.3 MySQL + PHP
 
Synapse india reviews on php and sql
Synapse india reviews on php and sqlSynapse india reviews on php and sql
Synapse india reviews on php and sql
 
FYBSC IT Web Programming Unit V Advanced PHP and MySQL
FYBSC IT Web Programming Unit V  Advanced PHP and MySQLFYBSC IT Web Programming Unit V  Advanced PHP and MySQL
FYBSC IT Web Programming Unit V Advanced PHP and MySQL
 
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
 
PHP DATABASE MANAGEMENT.pptx
PHP DATABASE MANAGEMENT.pptxPHP DATABASE MANAGEMENT.pptx
PHP DATABASE MANAGEMENT.pptx
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
 
Database presentation
Database presentationDatabase presentation
Database presentation
 
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docxModule 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
 
DIWE - Working with MySQL Databases
DIWE - Working with MySQL DatabasesDIWE - Working with MySQL Databases
DIWE - Working with MySQL Databases
 
Php summary
Php summaryPhp summary
Php summary
 
Web Application Development using PHP Chapter 7
Web Application Development using PHP Chapter 7Web Application Development using PHP Chapter 7
Web Application Development using PHP Chapter 7
 
DBD::SQLite
DBD::SQLiteDBD::SQLite
DBD::SQLite
 
9780538745840 ppt ch08
9780538745840 ppt ch089780538745840 ppt ch08
9780538745840 ppt ch08
 
Use sqlite
Use sqliteUse sqlite
Use sqlite
 
PHP 5 + MySQL 5 = A Perfect 10
PHP 5 + MySQL 5 = A Perfect 10PHP 5 + MySQL 5 = A Perfect 10
PHP 5 + MySQL 5 = A Perfect 10
 
Php mysq
Php mysqPhp mysq
Php mysq
 
Python database access
Python database accessPython database access
Python database access
 

Mais de Mohd Harris Ahmad Jaal

Mais de Mohd Harris Ahmad Jaal (20)

Fundamentals of Programming Chapter 7
Fundamentals of Programming Chapter 7Fundamentals of Programming Chapter 7
Fundamentals of Programming Chapter 7
 
Fundamentals of Programming Chapter 6
Fundamentals of Programming Chapter 6Fundamentals of Programming Chapter 6
Fundamentals of Programming Chapter 6
 
Fundamentals of Programming Chapter 4
Fundamentals of Programming Chapter 4Fundamentals of Programming Chapter 4
Fundamentals of Programming Chapter 4
 
Fundamentals of Programming Chapter 3
Fundamentals of Programming Chapter 3Fundamentals of Programming Chapter 3
Fundamentals of Programming Chapter 3
 
Fundamentals of Programming Chapter 2
Fundamentals of Programming Chapter 2Fundamentals of Programming Chapter 2
Fundamentals of Programming Chapter 2
 
Fundamentals of Programming Chapter 1
Fundamentals of Programming Chapter 1Fundamentals of Programming Chapter 1
Fundamentals of Programming Chapter 1
 
Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5
 
Web Application Development using PHP Chapter 6
Web Application Development using PHP Chapter 6Web Application Development using PHP Chapter 6
Web Application Development using PHP Chapter 6
 
Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5
 
Web Application Development using PHP Chapter 4
Web Application Development using PHP Chapter 4Web Application Development using PHP Chapter 4
Web Application Development using PHP Chapter 4
 
Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3
 
Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2
 
Web Application Development using PHP Chapter 1
Web Application Development using PHP Chapter 1Web Application Development using PHP Chapter 1
Web Application Development using PHP Chapter 1
 
Fundamentals of Computing Chapter 10
Fundamentals of Computing Chapter 10Fundamentals of Computing Chapter 10
Fundamentals of Computing Chapter 10
 
Fundamentals of Computing Chapter 9
Fundamentals of Computing Chapter 9Fundamentals of Computing Chapter 9
Fundamentals of Computing Chapter 9
 
Fundamentals of Computing Chapter 8
Fundamentals of Computing Chapter 8Fundamentals of Computing Chapter 8
Fundamentals of Computing Chapter 8
 
Fundamentals of Computing Chapter 7
Fundamentals of Computing Chapter 7Fundamentals of Computing Chapter 7
Fundamentals of Computing Chapter 7
 
Fundamentals of Computing Chapter 6
Fundamentals of Computing Chapter 6Fundamentals of Computing Chapter 6
Fundamentals of Computing Chapter 6
 
Fundamentals of Computing Chapter 5
Fundamentals of Computing Chapter 5Fundamentals of Computing Chapter 5
Fundamentals of Computing Chapter 5
 
Fundamentals of Computing Chapter 4
Fundamentals of Computing Chapter 4Fundamentals of Computing Chapter 4
Fundamentals of Computing Chapter 4
 

Último

Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Último (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 

Web Application Development using PHP Chapter 8

  • 1. CN5109 WEB APPLICATION DEVELOPMENT Chapter 8 MySQLi PHP Syntax – Working with Data
  • 2. MySQLi Insert Data • To insert data into MySQLi table, you would need to use SQL INSERT INTO command. • You can use INSERT INTO command into PHP function mysqli_query() to insert data into a MySQLi table.
  • 3. MySQLi Insert Data • Example: /* HTML FORM*/ <form action = “ " method = "post"> <label>Full Name :</label> <input type = "text" name = “fname" /> <br /> <br /> <input type = "submit" value ="Submit" name = "submit"/> <br /> </form>
  • 4. MySQLi Insert Data • Example: /* PHP FILE */ <?php // Connection to Database // Select Database $sql = "INSERT INTO table1(fname)VALUES ('".$_POST[“fname"]."')"; if (mysqli_query($conn, $sql)) { echo "New record created successfully"; } else { echo "Error: " . $sql . “ " . mysqli_error($conn); } mysqli_close($conn); ?>
  • 5. MySQLi Query Data • The SQL SELECT command is used to fetch data from MySQLi database. • You can use same SQL SELECT command into PHP function mysqli_query(). • This function is used to execute SQL command and later another PHP function mysqli_fetch_assoc() can be used to fetch all the selected data. • This function returns row as an associative array, a numeric array, or both. • This function returns FALSE if there are no more rows.
  • 6. MySQLi Query Data • Example: <?php // Connection to Database // Select Database $sql = 'SELECT fname FROM table1'; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { while($row = mysqli_fetch_assoc($result)) { echo "Name: " . $row["name"]. "<br>"; } } else { echo "0 result"; } mysqli_close($conn); ?>
  • 7. MySQLi Query Data • We have seen SQL SELECT command to fetch data from MySQLi table. • We can use a conditional clause called WHERE clause to filter out results. • Using WHERE clause, we can specify a selection criteria to select required records from a table. • The WHERE clause works like an if condition in any programming language. This clause is used to compare given value with the field value available in MySQLi table. • If given value from outside is equal to the available field value in MySQLi table, then it returns that row. • You can use same SQL SELECT command with WHERE CLAUSE into PHP function mysqli_query().
  • 8. MySQLi Query Data • Example: <?php // Connection to Database // Select Database $sql = 'SELECT fname FROM table1 WHERE fname=“ahmad”'; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { while($row = mysqli_fetch_assoc($result)) { echo "Name: " . $row["name"]. "<br>"; } } else { echo "0 result"; } mysqli_close($conn); ?>
  • 9. MySQLi UPDATE Data • There may be a requirement where existing data in a MySQLi table needs to be modified. • You can do so by using SQL UPDATE command. • This will modify any field value of any MySQLi table. • You can update one or more field altogether. • You can specify any condition using WHERE clause. • You can update values in a single table at a time. • You can use SQL UPDATE command with or without WHERE CLAUSE into PHP function mysqli_query().
  • 10. MySQLi UPDATE Data • Example: <?php // Connection to Database // Select Database $sql = ' UPDATE table1 SET fname="althamas" WHERE name="ram"'; if (mysqli_query($conn, $sql)) { echo "Record updated successfully"; } else { echo "Error updating record: " . mysqli_error($conn); } mysqli_close($conn); ?>
  • 11. MySQLi DELETE Data • If you want to delete a record from any MySQLi table, then you can use SQL command DELETE FROM. • If WHERE clause is not specified, then all the records will be deleted from the given MySQLi table. • You can specify any condition using WHERE clause. • You can delete records in a single table at a time. • You can use SQL DELETE command with or without WHERE CLAUSE into PHP function mysqli_query().