SlideShare a Scribd company logo
Publishing MySQL Data on the
Web
Introduction
• have installed and learned the basics of MySQL, a relational database engine, and
PHP, a server-side scripting language. Now you'll see how to use these two new
tools together to create a true database-driven Website!
• The whole idea of a database-driven Website is to allow the content of the site to
reside in a database, and for that content to be dynamically pulled from the
database to create Web pages for people to view with a regular Web browser
• ❑ The visitor's Web browser requests the Web page using a standard URL.
• ❑ The Web server software (Apache, IIS, or whatever) recognizes that the
requested file is a PHP script, and so the server interprets the file using its PHP
plug-in, before responding to the page request.
• ❑ Certain PHP commands (which you have yet to learn) connect to the MySQL
database and request the content that belongs in the Web page.
• ❑ The MySQL database responds by sending the requested content to the PHP
script.
• ❑ The PHP script stores the content into one or more PHP variables, and then uses
the now-familiar echo function to output the content as part of the Web page.
• ❑ The PHP plug-in finishes up by handing a copy of the HTML it has created to the
Web server.
• ❑ The Web server sends the HTML to the Web browser as it would a plain HTML
file, except that instead of coming directly from an HTML file, the page is the
output provided by the PHP plug-in.
Connecting to MySQL with PHP
Connect to our MySQL server.
• $dbcnx = mysql_connect('localhost', 'root', 'mypasswd');
– EX:
$dbcnx = @mysql_connect('localhost', 'root', 'mypasswd');
if (!$dbcnx) {
echo( '<p>Unable to connect to the ' .'database server at this time.</p>' );
exit();}
Select your database
– EX:
if (! @mysql_select_db('jokes') ) {
die( '<p>Unable to locate the joke ' .'database at this time.</p>' );
}
Sending SQL Queries with PHP
• EX: INSERT
$sql = "INSERT INTO tbcustomer VALUES(2,'Sopheap','F','Siem Reap','23233434')";
if ( @mysql_query($sql) ) {
echo('<p>Insert hery</p>');
}
else {
die('<p>Cannot Insert te: ' . mysql_error() .'</p>');}
• EX: DELETE
$sql = "DELETE FROM tbcustomer WHERE CustID=1";
if ( @mysql_query($sql) ) {
echo('<p>DELETED hery na</p>');
}
else {
die('<p>cannot delete te! : ' . mysql_error() .'</p>');
}
• EX: UPDATE
$sql = "UPDATE tbcustomer SET CustName='lola', Gender='F', Address='Phnom
Penh' WHERE CustID=1";
if ( @mysql_query($sql) ) {
echo('<p>Update complete hery na</p>');
}
else {
die('<p>Cannot delete te! ' . mysql_error() .'</p>');
}
Handling SELECT Result Sets
• For SELECT queries this just isn't enough.
• In addition to indicating whether the query succeeded or failed, PHP must also
receive the results of the query.
– EX:
$result = @mysql_query('SELECT* FROM tbcustomer;');
if (!$result)
{
die('<p>Error performing query: ' . mysql_error() .'</p>');
}
– EX:
$result = @mysql_query('SELECT* FROM tbcustomer;');
if (!$result){
die('<p>Error performing query: ' . mysql_error() .'</p>');}
while ( $row = mysql_fetch_array($result) ) {
echo('<p>' . $row['CustID'] . '|' . $row['CustName'] . '|' . $row['Gender'] . '|' .
$row['Address'] . '|' . $row['Phone'] . '</p>');
}
Inserting Data into the Database
• EX:
$sql = "INSERT INTO tbcustomer SET CustID=1, CustName='lola', Gender='M',
Address='SR', Phone='2343434'";
if (@mysql_query($sql)) {
echo('<p>Your joke has been added.</p>');
}
else {
echo('<p>Error adding submitted joke: ' . mysql_error() . '</p>');
}
Delete Data in the Database
• EX:
$sql = 'DELETE FROM tbcustomer WHERE CustID=1';
if (@mysql_query($sql))
{
echo('<p>has been deleted.</p>');
}
else
{
echo('<p>Error deleting joke: ' . mysql_error() . '</p>');
}
Ch7(publishing my sql data on the web)
Ch7(publishing my sql data on the web)
Ad

Recommended

Php basics
Php basics
Egerton University
 
Rack
Rack
Sarah Allen
 
Web Application Development using PHP Chapter 7
Web Application Development using PHP Chapter 7
Mohd Harris Ahmad Jaal
 
Transforming WordPress Search and Query Performance with Elasticsearch
Transforming WordPress Search and Query Performance with Elasticsearch
Taylor Lovett
 
Zend Con 2008 Slides
Zend Con 2008 Slides
mkherlakian
 
Inside Bokete: Web Application with Mojolicious and others
Inside Bokete: Web Application with Mojolicious and others
Yusuke Wada
 
What You Missed in Computer Science
What You Missed in Computer Science
Taylor Lovett
 
Amp and higher computing science
Amp and higher computing science
Charlie Love
 
Modernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with Elasticsearch
Taylor Lovett
 
Memcache basics on google app engine
Memcache basics on google app engine
Ido Green
 
The JSON REST API for WordPress
The JSON REST API for WordPress
Taylor Lovett
 
Php basic for vit university
Php basic for vit university
Mandakini Kumari
 
Express Presentation
Express Presentation
aaronheckmann
 
Rupy2012 ArangoDB Workshop Part2
Rupy2012 ArangoDB Workshop Part2
ArangoDB Database
 
Ako prepojiť aplikáciu s Elasticsearch
Ako prepojiť aplikáciu s Elasticsearch
bart-sk
 
Real-time search in Drupal. Meet Elasticsearch
Real-time search in Drupal. Meet Elasticsearch
Alexei Gorobets
 
Working with WP_Query in WordPress
Working with WP_Query in WordPress
topher1kenobe
 
Chandra Prakash Thapa: Make a WordPress Multisite in 20 mins
Chandra Prakash Thapa: Make a WordPress Multisite in 20 mins
wpnepal
 
JSON REST API for WordPress
JSON REST API for WordPress
Taylor Lovett
 
Real-time search in Drupal with Elasticsearch @Moldcamp
Real-time search in Drupal with Elasticsearch @Moldcamp
Alexei Gorobets
 
Worcamp2012 make a wordpress multisite in 20mins
Worcamp2012 make a wordpress multisite in 20mins
Chandra Prakash Thapa
 
The hitchhiker's guide to the Webpack - Sara Vieira - Codemotion Amsterdam 2017
The hitchhiker's guide to the Webpack - Sara Vieira - Codemotion Amsterdam 2017
Codemotion
 
Ruby conf 2011, Create your own rails framework
Ruby conf 2011, Create your own rails framework
Pankaj Bhageria
 
Introduction to CouchDB
Introduction to CouchDB
OpusVL
 
Scalable web application architecture
Scalable web application architecture
postrational
 
MuleSoft ESB Message Enricher
MuleSoft ESB Message Enricher
akashdprajapati
 
User Credential handling in Web Applications done right
User Credential handling in Web Applications done right
tladesignz
 
Introduction to AJAX
Introduction to AJAX
Abzetdin Adamov
 
Final morris esri_nwgis_lidar
Final morris esri_nwgis_lidar
Eric Morris
 
Appendex e
Appendex e
swavicky
 

More Related Content

What's hot (20)

Modernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with Elasticsearch
Taylor Lovett
 
Memcache basics on google app engine
Memcache basics on google app engine
Ido Green
 
The JSON REST API for WordPress
The JSON REST API for WordPress
Taylor Lovett
 
Php basic for vit university
Php basic for vit university
Mandakini Kumari
 
Express Presentation
Express Presentation
aaronheckmann
 
Rupy2012 ArangoDB Workshop Part2
Rupy2012 ArangoDB Workshop Part2
ArangoDB Database
 
Ako prepojiť aplikáciu s Elasticsearch
Ako prepojiť aplikáciu s Elasticsearch
bart-sk
 
Real-time search in Drupal. Meet Elasticsearch
Real-time search in Drupal. Meet Elasticsearch
Alexei Gorobets
 
Working with WP_Query in WordPress
Working with WP_Query in WordPress
topher1kenobe
 
Chandra Prakash Thapa: Make a WordPress Multisite in 20 mins
Chandra Prakash Thapa: Make a WordPress Multisite in 20 mins
wpnepal
 
JSON REST API for WordPress
JSON REST API for WordPress
Taylor Lovett
 
Real-time search in Drupal with Elasticsearch @Moldcamp
Real-time search in Drupal with Elasticsearch @Moldcamp
Alexei Gorobets
 
Worcamp2012 make a wordpress multisite in 20mins
Worcamp2012 make a wordpress multisite in 20mins
Chandra Prakash Thapa
 
The hitchhiker's guide to the Webpack - Sara Vieira - Codemotion Amsterdam 2017
The hitchhiker's guide to the Webpack - Sara Vieira - Codemotion Amsterdam 2017
Codemotion
 
Ruby conf 2011, Create your own rails framework
Ruby conf 2011, Create your own rails framework
Pankaj Bhageria
 
Introduction to CouchDB
Introduction to CouchDB
OpusVL
 
Scalable web application architecture
Scalable web application architecture
postrational
 
MuleSoft ESB Message Enricher
MuleSoft ESB Message Enricher
akashdprajapati
 
User Credential handling in Web Applications done right
User Credential handling in Web Applications done right
tladesignz
 
Introduction to AJAX
Introduction to AJAX
Abzetdin Adamov
 
Modernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with Elasticsearch
Taylor Lovett
 
Memcache basics on google app engine
Memcache basics on google app engine
Ido Green
 
The JSON REST API for WordPress
The JSON REST API for WordPress
Taylor Lovett
 
Php basic for vit university
Php basic for vit university
Mandakini Kumari
 
Express Presentation
Express Presentation
aaronheckmann
 
Rupy2012 ArangoDB Workshop Part2
Rupy2012 ArangoDB Workshop Part2
ArangoDB Database
 
Ako prepojiť aplikáciu s Elasticsearch
Ako prepojiť aplikáciu s Elasticsearch
bart-sk
 
Real-time search in Drupal. Meet Elasticsearch
Real-time search in Drupal. Meet Elasticsearch
Alexei Gorobets
 
Working with WP_Query in WordPress
Working with WP_Query in WordPress
topher1kenobe
 
Chandra Prakash Thapa: Make a WordPress Multisite in 20 mins
Chandra Prakash Thapa: Make a WordPress Multisite in 20 mins
wpnepal
 
JSON REST API for WordPress
JSON REST API for WordPress
Taylor Lovett
 
Real-time search in Drupal with Elasticsearch @Moldcamp
Real-time search in Drupal with Elasticsearch @Moldcamp
Alexei Gorobets
 
Worcamp2012 make a wordpress multisite in 20mins
Worcamp2012 make a wordpress multisite in 20mins
Chandra Prakash Thapa
 
The hitchhiker's guide to the Webpack - Sara Vieira - Codemotion Amsterdam 2017
The hitchhiker's guide to the Webpack - Sara Vieira - Codemotion Amsterdam 2017
Codemotion
 
Ruby conf 2011, Create your own rails framework
Ruby conf 2011, Create your own rails framework
Pankaj Bhageria
 
Introduction to CouchDB
Introduction to CouchDB
OpusVL
 
Scalable web application architecture
Scalable web application architecture
postrational
 
MuleSoft ESB Message Enricher
MuleSoft ESB Message Enricher
akashdprajapati
 
User Credential handling in Web Applications done right
User Credential handling in Web Applications done right
tladesignz
 

Viewers also liked (20)

Final morris esri_nwgis_lidar
Final morris esri_nwgis_lidar
Eric Morris
 
Appendex e
Appendex e
swavicky
 
Chapter 4 Form Factors & Power Supplies
Chapter 4 Form Factors & Power Supplies
Patty Ramsey
 
Chapter 4 Form Factors Power Supplies
Chapter 4 Form Factors Power Supplies
Patty Ramsey
 
Introduction to PHP - SDPHP
Introduction to PHP - SDPHP
Eric Johnson
 
Ch07
Ch07
swavicky
 
LiDAR Aided Decision Making
LiDAR Aided Decision Making
Lidar Blog
 
WE1.L10 - GRACE Applications to Regional Hydrology and Water Resources
WE1.L10 - GRACE Applications to Regional Hydrology and Water Resources
grssieee
 
final emoji-board EMAIL ME NOWSWAG11
final emoji-board EMAIL ME NOWSWAG11
Joe Humphreys
 
Appendex b
Appendex b
swavicky
 
Preparing LiDAR for Use in ArcGIS 10.1 with the Data Interoperability Extension
Preparing LiDAR for Use in ArcGIS 10.1 with the Data Interoperability Extension
Safe Software
 
Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)
Chhom Karath
 
eMail 101 (2) Class for Selfhelp Virtual Senior Center
eMail 101 (2) Class for Selfhelp Virtual Senior Center
SnowSugar Video
 
5 Accessing Information Resources
5 Accessing Information Resources
Patty Ramsey
 
PHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet Solution
Mazenetsolution
 
Ch5(ms access with php)
Ch5(ms access with php)
Chhom Karath
 
Appendex g
Appendex g
swavicky
 
PHP 5.3 Part 1 - Introduction to PHP 5.3
PHP 5.3 Part 1 - Introduction to PHP 5.3
melechi
 
Survey Grade LiDAR Technologies for Transportation Engineering
Survey Grade LiDAR Technologies for Transportation Engineering
Quantum Spatial
 
Setting up a gmail account
Setting up a gmail account
keelyswitzer
 
Final morris esri_nwgis_lidar
Final morris esri_nwgis_lidar
Eric Morris
 
Appendex e
Appendex e
swavicky
 
Chapter 4 Form Factors & Power Supplies
Chapter 4 Form Factors & Power Supplies
Patty Ramsey
 
Chapter 4 Form Factors Power Supplies
Chapter 4 Form Factors Power Supplies
Patty Ramsey
 
Introduction to PHP - SDPHP
Introduction to PHP - SDPHP
Eric Johnson
 
LiDAR Aided Decision Making
LiDAR Aided Decision Making
Lidar Blog
 
WE1.L10 - GRACE Applications to Regional Hydrology and Water Resources
WE1.L10 - GRACE Applications to Regional Hydrology and Water Resources
grssieee
 
final emoji-board EMAIL ME NOWSWAG11
final emoji-board EMAIL ME NOWSWAG11
Joe Humphreys
 
Appendex b
Appendex b
swavicky
 
Preparing LiDAR for Use in ArcGIS 10.1 with the Data Interoperability Extension
Preparing LiDAR for Use in ArcGIS 10.1 with the Data Interoperability Extension
Safe Software
 
Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)
Chhom Karath
 
eMail 101 (2) Class for Selfhelp Virtual Senior Center
eMail 101 (2) Class for Selfhelp Virtual Senior Center
SnowSugar Video
 
5 Accessing Information Resources
5 Accessing Information Resources
Patty Ramsey
 
PHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet Solution
Mazenetsolution
 
Ch5(ms access with php)
Ch5(ms access with php)
Chhom Karath
 
Appendex g
Appendex g
swavicky
 
PHP 5.3 Part 1 - Introduction to PHP 5.3
PHP 5.3 Part 1 - Introduction to PHP 5.3
melechi
 
Survey Grade LiDAR Technologies for Transportation Engineering
Survey Grade LiDAR Technologies for Transportation Engineering
Quantum Spatial
 
Setting up a gmail account
Setting up a gmail account
keelyswitzer
 
Ad

Similar to Ch7(publishing my sql data on the web) (20)

Connecting to my sql using PHP
Connecting to my sql using PHP
Nisa Soomro
 
PHP - Getting good with MySQL part II
PHP - Getting good with MySQL part II
Firdaus Adib
 
3-Chapter-Edit.pptx debre tabour university
3-Chapter-Edit.pptx debre tabour university
alemunuruhak9
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
Php summary
Php summary
Michelle Darling
 
PHP and MySQL.pptx
PHP and MySQL.pptx
natesanp1234
 
introduction to backend with php 8.X - slide.pptx
introduction to backend with php 8.X - slide.pptx
geremilibrary
 
Php and MySQL Web Development
Php and MySQL Web Development
w3ondemand
 
Php modul-3
Php modul-3
Kristophorus Hadiono
 
CHAPTER six DataBase Driven Websites.pptx
CHAPTER six DataBase Driven Websites.pptx
KelemAlebachew
 
chapter_Seven Database manipulation using php.pptx
chapter_Seven Database manipulation using php.pptx
Getawu
 
Php workshop L04 database
Php workshop L04 database
Mohammad Tahsin Alshalabi
 
PHP with MySQL
PHP with MySQL
wahidullah mudaser
 
Database Connectivity in PHP
Database Connectivity in PHP
Taha Malampatti
 
PHP - Introduction to PHP Date and Time Functions
PHP - Introduction to PHP Date and Time Functions
Vibrant Technologies & Computers
 
Lecture1 introduction by okello erick
Lecture1 introduction by okello erick
okelloerick
 
PHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHP
Dave Stokes
 
PHP tutorials , php tutorials for beginners , tutorials for php
PHP tutorials , php tutorials for beginners , tutorials for php
aimaq9a
 
Lecture12
Lecture12
Châu Thanh Chương
 
Php reports sumit
Php reports sumit
Sumit Biswas
 
Connecting to my sql using PHP
Connecting to my sql using PHP
Nisa Soomro
 
PHP - Getting good with MySQL part II
PHP - Getting good with MySQL part II
Firdaus Adib
 
3-Chapter-Edit.pptx debre tabour university
3-Chapter-Edit.pptx debre tabour university
alemunuruhak9
 
PHP and MySQL.pptx
PHP and MySQL.pptx
natesanp1234
 
introduction to backend with php 8.X - slide.pptx
introduction to backend with php 8.X - slide.pptx
geremilibrary
 
Php and MySQL Web Development
Php and MySQL Web Development
w3ondemand
 
CHAPTER six DataBase Driven Websites.pptx
CHAPTER six DataBase Driven Websites.pptx
KelemAlebachew
 
chapter_Seven Database manipulation using php.pptx
chapter_Seven Database manipulation using php.pptx
Getawu
 
Database Connectivity in PHP
Database Connectivity in PHP
Taha Malampatti
 
Lecture1 introduction by okello erick
Lecture1 introduction by okello erick
okelloerick
 
PHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHP
Dave Stokes
 
PHP tutorials , php tutorials for beginners , tutorials for php
PHP tutorials , php tutorials for beginners , tutorials for php
aimaq9a
 
Ad

More from Chhom Karath (20)

set1.pdf
set1.pdf
Chhom Karath
 
Set1.pptx
Set1.pptx
Chhom Karath
 
orthodontic patient education.pdf
orthodontic patient education.pdf
Chhom Karath
 
New ton 3.pdf
New ton 3.pdf
Chhom Karath
 
ច្បាប់ញូតុនទី៣.pptx
ច្បាប់ញូតុនទី៣.pptx
Chhom Karath
 
Control tipping.pptx
Control tipping.pptx
Chhom Karath
 
Bulbous loop.pptx
Bulbous loop.pptx
Chhom Karath
 
brush teeth.pptx
brush teeth.pptx
Chhom Karath
 
bracket size.pptx
bracket size.pptx
Chhom Karath
 
arch form KORI copy.pptx
arch form KORI copy.pptx
Chhom Karath
 
Bracket size
Bracket size
Chhom Karath
 
Couple
Couple
Chhom Karath
 
ច្បាប់ញូតុនទី៣
ច្បាប់ញូតុនទី៣
Chhom Karath
 
Game1
Game1
Chhom Karath
 
Shoe horn loop
Shoe horn loop
Chhom Karath
 
Opus loop
Opus loop
Chhom Karath
 
V bend
V bend
Chhom Karath
 
Closing loop
Closing loop
Chhom Karath
 
Maxillary arch form
Maxillary arch form
Chhom Karath
 
Front face analysis
Front face analysis
Chhom Karath
 

Recently uploaded (20)

A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
Daily Lesson Log MATATAG ICT TEchnology 8
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
Daily Lesson Log MATATAG ICT TEchnology 8
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 

Ch7(publishing my sql data on the web)

  • 2. Introduction • have installed and learned the basics of MySQL, a relational database engine, and PHP, a server-side scripting language. Now you'll see how to use these two new tools together to create a true database-driven Website! • The whole idea of a database-driven Website is to allow the content of the site to reside in a database, and for that content to be dynamically pulled from the database to create Web pages for people to view with a regular Web browser
  • 3. • ❑ The visitor's Web browser requests the Web page using a standard URL. • ❑ The Web server software (Apache, IIS, or whatever) recognizes that the requested file is a PHP script, and so the server interprets the file using its PHP plug-in, before responding to the page request. • ❑ Certain PHP commands (which you have yet to learn) connect to the MySQL database and request the content that belongs in the Web page. • ❑ The MySQL database responds by sending the requested content to the PHP script. • ❑ The PHP script stores the content into one or more PHP variables, and then uses the now-familiar echo function to output the content as part of the Web page. • ❑ The PHP plug-in finishes up by handing a copy of the HTML it has created to the Web server. • ❑ The Web server sends the HTML to the Web browser as it would a plain HTML file, except that instead of coming directly from an HTML file, the page is the output provided by the PHP plug-in.
  • 4. Connecting to MySQL with PHP Connect to our MySQL server. • $dbcnx = mysql_connect('localhost', 'root', 'mypasswd'); – EX: $dbcnx = @mysql_connect('localhost', 'root', 'mypasswd'); if (!$dbcnx) { echo( '<p>Unable to connect to the ' .'database server at this time.</p>' ); exit();} Select your database – EX: if (! @mysql_select_db('jokes') ) { die( '<p>Unable to locate the joke ' .'database at this time.</p>' ); }
  • 5. Sending SQL Queries with PHP • EX: INSERT $sql = "INSERT INTO tbcustomer VALUES(2,'Sopheap','F','Siem Reap','23233434')"; if ( @mysql_query($sql) ) { echo('<p>Insert hery</p>'); } else { die('<p>Cannot Insert te: ' . mysql_error() .'</p>');} • EX: DELETE $sql = "DELETE FROM tbcustomer WHERE CustID=1"; if ( @mysql_query($sql) ) { echo('<p>DELETED hery na</p>'); } else { die('<p>cannot delete te! : ' . mysql_error() .'</p>'); }
  • 6. • EX: UPDATE $sql = "UPDATE tbcustomer SET CustName='lola', Gender='F', Address='Phnom Penh' WHERE CustID=1"; if ( @mysql_query($sql) ) { echo('<p>Update complete hery na</p>'); } else { die('<p>Cannot delete te! ' . mysql_error() .'</p>'); }
  • 7. Handling SELECT Result Sets • For SELECT queries this just isn't enough. • In addition to indicating whether the query succeeded or failed, PHP must also receive the results of the query. – EX: $result = @mysql_query('SELECT* FROM tbcustomer;'); if (!$result) { die('<p>Error performing query: ' . mysql_error() .'</p>'); } – EX: $result = @mysql_query('SELECT* FROM tbcustomer;'); if (!$result){ die('<p>Error performing query: ' . mysql_error() .'</p>');} while ( $row = mysql_fetch_array($result) ) { echo('<p>' . $row['CustID'] . '|' . $row['CustName'] . '|' . $row['Gender'] . '|' . $row['Address'] . '|' . $row['Phone'] . '</p>'); }
  • 8. Inserting Data into the Database • EX: $sql = "INSERT INTO tbcustomer SET CustID=1, CustName='lola', Gender='M', Address='SR', Phone='2343434'"; if (@mysql_query($sql)) { echo('<p>Your joke has been added.</p>'); } else { echo('<p>Error adding submitted joke: ' . mysql_error() . '</p>'); } Delete Data in the Database • EX: $sql = 'DELETE FROM tbcustomer WHERE CustID=1'; if (@mysql_query($sql)) { echo('<p>has been deleted.</p>'); } else { echo('<p>Error deleting joke: ' . mysql_error() . '</p>'); }

Editor's Notes

  • #10: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <style type="text/css"> .error{ background: 'red';} </style> <?php $cls1="";$cls2="";$cls3="";$cls4=""; $st=""; function clearForm() { $_POST['txtPID']=""; $_POST['txtProName']=""; $_POST['txtProQty']=""; $_POST['txtUnitPrice']=""; $_POST['txtTotal']=""; } if(isset($_POST['btNew'])) { clearForm(); } else if(isset($_POST['btSearch'])) { $dbcnx = @mysql_connect('localhost', 'root'); if (!$dbcnx) { echo( '<p>Unable to connect to the ' .'database server at this time.</p>' ); exit(); } if (! @mysql_select_db('db2') ) { die( '<p>Unable to locate ' .'database at this time.</p>' ); } $result = @mysql_query('SELECT* FROM tbproduct WHERE ProID=' . $_POST['txtPID']); if (!$result) { die('<p>Error performing query: ' . mysql_error() .'</p>'); } $st="<table border=1><tr><th>ProID</th><th>ProName</th><th>Quantity</th><th>UnitPrice</th><th>Total</th></tr>"; while ( $row = mysql_fetch_array($result) ) { $st.="<tr><td>" . $row['ProID'] . "</td><td>" . $row['ProName'] . "</td><td>" . $row['Qty'] . "</td><td>" . $row['UnitPrice'] . "$</td><td>" . $row['UnitPrice']*$row['Qty'] . "$</td></tr>"; } $st.="</table>"; } else if(isset($_POST['btShow'])) { $dbcnx = @mysql_connect('localhost', 'root'); if (!$dbcnx) { echo( '<p>Unable to connect to the ' .'database server at this time.</p>' ); exit(); } if (! @mysql_select_db('db2') ) { die( '<p>Unable to locate the joke ' .'database at this time.</p>' ); } $result = @mysql_query('SELECT* FROM tbproduct;'); if (!$result) { die('<p>Error performing query: ' . mysql_error() .'</p>'); } $st="<table border=1><tr><th>ProID</th><th>ProName</th><th>Quantity</th><th>UnitPrice</th><th>Total</th></tr>"; while ( $row = mysql_fetch_array($result) ) { $st.="<tr><td>" . $row['ProID'] . "</td><td>" . $row['ProName'] . "</td><td>" . $row['Qty'] . "</td><td>" . $row['UnitPrice'] . "$</td><td>" . $row['UnitPrice']*$row['Qty'] . "$</td></tr>"; } $st.="</table>"; } else if(isset($_POST['btDelete'])) { if(!empty($_POST['txtPID'])) { $dbcnx = @mysql_connect('localhost', 'root'); if (!$dbcnx) { echo( '<p>Unable to connect to the ' .'database server at this time.</p>' ); exit(); } if (! @mysql_select_db('db2') ) { die( '<p>Unable to locate ' .'database at this time.</p>' ); } $pID=$_POST['txtPID']; $sql = 'DELETE FROM tbproduct WHERE ProID=' . $pID ; if (@mysql_query($sql)) { echo('<p>has been deleted.</p>'); } else { echo('<p>Error deleting joke: ' . mysql_error() . '</p>'); } } } else if(isset($_POST['btInsert']) or isset($_POST['btUpdate']) or isset($_POST['btDelete'])) { $proID=$_POST['txtPID']; $proName=$_POST['txtProName']; $qty=$_POST['txtProQty']; $unitprice=$_POST['txtUnitPrice']; if(empty($_POST['txtPID'])) { $cls1="error"; } else if(empty($_POST['txtProName'])) { $cls2="error"; } else if(empty($_POST['txtProQty'])) { $cls3="error"; } else if(empty($_POST['txtUnitPrice'])) { $cls4="error"; } else if(isset($_POST['btInsert'])) { $proID=$_POST['txtPID']; $proName=$_POST['txtProName']; $qty=$_POST['txtProQty']; $unitprice=$_POST['txtUnitPrice']; if(empty($_POST['txtPID'])) { $cls1="error"; } else if(empty($_POST['txtProName'])) { $cls2="error"; } else if(empty($_POST['txtProQty'])) { $cls3="error"; } else if(empty($_POST['txtUnitPrice'])) { $cls4="error"; } else { $dbcnx = @mysql_connect('localhost', 'root'); if (!$dbcnx) { echo( '<p>Unable to connect to the ' .'database server at this time.</p>' ); exit(); } if (! @mysql_select_db('db2') ) { die( '<p>Unable to locate the db2 ' .'database at this time.</p>' ); } $sql = "INSERT INTO tbproduct SET ProID=" . $proID . " , ProName='" . $proName . "', Qty=" . $qty . ", UnitPrice=" . $unitprice; if (@mysql_query($sql)) { echo('<p>You has been added.</p>'); } else { echo('<p>Error adding submitted table: ' . mysql_error() . '</p>'); } } } else if(isset($_POST['btUpdate'])) { $dbcnx = @mysql_connect('localhost', 'root'); if (!$dbcnx) { echo( '<p>Unable to connect to the ' .'database server at this time.</p>' ); exit(); } if (! @mysql_select_db('db2') ) { die( '<p>Unable to locate ' .'database at this time.</p>' ); } $sql = "UPDATE tbproduct SET ProName='" . $_POST['txtProName'] . "', Qty=" . $_POST['txtProQty'] . " , UnitPrice=" . $_POST['txtUnitPrice'] . " WHERE ProID=" . $_POST['txtPID']; @mysql_query($sql) ; } } ?> </head> <body> <form method="post" action=""> <table> <tr><td><label for="txtPID" class="<?php print $cls1; ?>">ProID:</label></td><td><input type="text" name="txtPID" value="<?php print $_POST['txtPID']; ?>"/></td><td><input type="submit" name="btNew" value="New"/><input type="submit" name="btSearch" value="SeachID"/></td></tr> <tr><td><label for="txtProName" class="<?php print $cls2; ?>">ProNAME:</label></td><td><input type="text" name="txtProName" value="<?php print $_POST['txtProName']; ?>"/></td><td><input type="submit" name="btInsert" value="Insert"/></td></tr> <tr><td><label for="txtProQty" class="<?php print $cls3; ?>">QTY :</label></td><td><input type="text" name="txtProQty" value="<?php print $_POST['txtProQty']; ?>"/></td><td><input type="submit" name="btUpdate" value="Update"/></td></tr> <tr><td><label for="txtUnitPrice" class="<?php print $_POST['txtUnitPrice']; ?>">Unit price :</label></td><td><input type="text" name="txtUnitPrice" value="<?php print $_POST['txtUnitPrice']; ?>"/></td><td><input type="submit" name="btDelete" value="Delete"/></td></tr> <tr><td><label for="txtTotal">Total :</label></td><td ><input type="text" name="txtTotal" value="<?php print $total; ?>"/></td><td><input type="submit" name="btShow" value="Show data"/></td></tr> </table> <?php print $st; ?> </form> </body> </html>
  • #11: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <style type="text/css"> .error{ background: 'red';} </style> <?php $cls1="";$cls2="";$cls3=""; function clearForm() { $_POST['txtPID']=""; $_POST['txtProName']=""; $_POST['txtLink']=""; } if(isset($_POST['btNew'])) { clearForm(); } else if(isset($_POST['btSearch'])) { $dbcnx = @mysql_connect('localhost', 'root'); if (!$dbcnx) { echo( '<p>Unable to connect to the ' .'database server at this time.</p>' ); exit(); } if (! @mysql_select_db('db1') ) { die( '<p>Unable to locate the joke ' .'database at this time.</p>' ); } $result = @mysql_query("SELECT * FROM tbproduct WHERE productName='" . $_POST['txtProName'] . "'" ); if (!$result) { die('<p>Error performing query: ' . mysql_error() .'</p>'); } $st="<table border=1 width='100%'><tr><th>Product ID</th><th>Product Name</th></tr>"; while ( $row = mysql_fetch_array($result) ) { $st.="<tr><td>" . $row['ProductID'] . "</td><td><a href='" . $row['Linksite'] . "'>" . $row['ProductName'] . "</td></tr>"; } $st.="</table>"; } else if(isset($_POST['btShow'])) { $dbcnx = @mysql_connect('localhost', 'root'); if (!$dbcnx) { echo( '<p>Unable to connect to the ' .'database server at this time.</p>' ); exit(); } if (! @mysql_select_db('db1') ) { die( '<p>Unable to locate the joke ' .'database at this time.</p>' ); } $result = @mysql_query('SELECT * FROM tbproduct;'); if (!$result) { die('<p>Error performing query: ' . mysql_error() .'</p>'); } $st="<table border=1 width='100%'><tr><th>Product ID</th><th>Product Name</th></tr>"; while ( $row = mysql_fetch_array($result) ) { $st.="<tr><td>" . $row['ProductID'] . "</td><td><a href='" . $row['Linksite'] . "?v1=" . $row['ProductID'] . "'>" . $row['ProductName'] . "</a></td></tr>"; } $st.="</table>"; } else if(isset($_POST['btDelete'])) { if(!empty($_POST['txtPID'])) { $dbcnx = @mysql_connect('localhost', 'root'); if (!$dbcnx) { echo( '<p>Unable to connect to the ' .'database server at this time.</p>' ); exit(); } if (! @mysql_select_db('db1') ) { die( '<p>Unable to locate ' .'database at this time.</p>' ); } $pID=$_POST['txtPID']; $sql = 'DELETE FROM tbproduct WHERE ProductID=' . $pID ; if (@mysql_query($sql)) { echo('<p>has been deleted.</p>'); } else { echo('<p>Error deleting joke: ' . mysql_error() . '</p>'); } } } else if(isset($_POST['btInsert']) or isset($_POST['btUpdate'])) { $proID=$_POST['txtPID']; $proName=$_POST['txtProName']; $link=$_POST['txtLink']; if(empty($_POST['txtPID'])) { $cls1="error"; } else if(empty($_POST['txtProName'])) { $cls2="error"; } else if(empty($_POST['txtLink'])) { $cls3="error"; } else if(isset($_POST['btInsert'])) { $proID=$_POST['txtPID']; $proName=$_POST['txtProName']; $link=$_POST['txtLink']; $dbcnx = @mysql_connect('localhost', 'root'); if (!$dbcnx) { echo( '<p>Unable to connect to the ' .'database server at this time.</p>' ); exit(); } if (! @mysql_select_db('db1') ) { die( '<p>Unable to locate the db2 ' .'database at this time.</p>' ); } $sql = "INSERT INTO tbproduct SET ProductID=" . $proID . " , ProductName='" . $proName . "', Linksite='" . $link ."'"; if (@mysql_query($sql)) { echo('<p>You has been added.</p>'); } else { echo('<p>Error adding submitted table: ' . mysql_error() . '</p>'); } } else if(isset($_POST['btUpdate'])) { $dbcnx = @mysql_connect('localhost', 'root'); if (!$dbcnx) { echo( '<p>Unable to connect to the ' .'database server at this time.</p>' ); exit(); } if (! @mysql_select_db('db1') ) { die( '<p>Unable to locate ' .'database at this time.</p>' ); } $sql = "UPDATE tbproduct SET ProductName='" . $_POST['txtProName'] . "', Linksite='" . $_POST['txtLink'] . "' WHERE ProductID=" . $_POST['txtPID']; if (@mysql_query($sql)) { echo('<p>You update successfully.</p>'); } else { echo('<p>Error adding submitted table: ' . mysql_error() . '</p>'); } } else { clearForm(); } } ?> </head> <body> <form method="post" action=""> <table border=1 width="100%"> <tr><td><label for="txtPID" class="<?php print $cls1; ?>">ProID:</label></td><td><input type="text" name="txtPID" value="<?php print $_POST['txtPID']; ?>"/></td></tr> <tr><td><label for="txtProName" class="<?php print $cls2; ?>">ProNAME:</label></td><td><input type="text" name="txtProName" value="<?php print $_POST['txtProName']; ?>"/></td></tr> <tr><td><label for="txtLink" class="<?php print $cls3; ?>">Link site :</label></td><td><input type="text" name="txtLink" value="<?php print $_POST['txtLink']; ?>"/></tr> <tr><td colspan="2"><input type="submit" name="btInsert" value="Insert"/><input type="submit" name="btUpdate" value="Update"/><input type="submit" name="btDelete" value="Delete"/><input type="submit" name="btShow" value="Show data"/><input type="submit" name="btNew" value="New"/><input type="submit" name="btSearch" value="SeachID"/></td></tr> </table> <?php print $st; ?> </form> </body> </html> //======================================================= <?php $dbcnx = @mysql_connect('localhost', 'root'); if (!$dbcnx) { echo( '<p>Unable to connect to the ' .'database server at this time.</p>' ); exit(); } if (! @mysql_select_db('db1') ) { die( '<p>Unable to locate the joke ' .'database at this time.</p>' ); } $result = @mysql_query('SELECT * FROM tbsong WHERE ProductID=' . $_GET['v1']); if (!$result) { die('<p>Error performing query: ' . mysql_error() .'</p>'); } $st="<table border=1 width='100%'><tr><th>Song ID</th><th>Song Name</th><th>Vol</td></tr>"; while ( $row = mysql_fetch_array($result) ) { $st.="<tr><td>" . $row['SongID'] . "</td><td><a href='" . $row['Linksite'] . "' >" . $row['SongName'] . "</td><td>" . $row['Vol'] . "</td></tr>"; } $st.="</table>"; print $st; ?>