SlideShare a Scribd company logo
1 of 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().

More Related Content

What's hot (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
 

Similar to Web Application Development using PHP Chapter 8

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 sqlsaritasingh19866
 
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 MySQLArti Parab Academics
 
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
 
PHP DATABASE MANAGEMENT.pptx
PHP DATABASE MANAGEMENT.pptxPHP DATABASE MANAGEMENT.pptx
PHP DATABASE MANAGEMENT.pptxCynthiaKendi1
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2ADARSH BHATT
 
Database presentation
Database presentationDatabase presentation
Database presentationwebhostingguy
 
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.docxmoirarandell
 
DIWE - Working with MySQL Databases
DIWE - Working with MySQL DatabasesDIWE - Working with MySQL Databases
DIWE - Working with MySQL DatabasesRasan Samarasinghe
 
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 7Mohd Harris Ahmad Jaal
 
DBD::SQLite
DBD::SQLiteDBD::SQLite
DBD::SQLitecharsbar
 
9780538745840 ppt ch08
9780538745840 ppt ch089780538745840 ppt ch08
9780538745840 ppt ch08Terry 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 10Adam Trachtenberg
 

Similar to 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
 

More from Mohd Harris Ahmad Jaal

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 6Mohd Harris Ahmad Jaal
 
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 5Mohd Harris Ahmad Jaal
 
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 4Mohd Harris Ahmad Jaal
 
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 3Mohd Harris Ahmad Jaal
 
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 2Mohd Harris Ahmad Jaal
 
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 1Mohd Harris Ahmad Jaal
 

More from 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
 

Recently uploaded

History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 

Recently uploaded (20)

History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 

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().