SlideShare une entreprise Scribd logo
1  sur  10
Télécharger pour lire hors ligne
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)

Contenu connexe

Tendances

Modernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with ElasticsearchModernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with ElasticsearchTaylor Lovett
 
Memcache basics on google app engine
Memcache basics on google app engineMemcache basics on google app engine
Memcache basics on google app engineIdo Green
 
The JSON REST API for WordPress
The JSON REST API for WordPressThe JSON REST API for WordPress
The JSON REST API for WordPressTaylor Lovett
 
Php basic for vit university
Php basic for vit universityPhp basic for vit university
Php basic for vit universityMandakini Kumari
 
Express Presentation
Express PresentationExpress Presentation
Express Presentationaaronheckmann
 
Rupy2012 ArangoDB Workshop Part2
Rupy2012 ArangoDB Workshop Part2Rupy2012 ArangoDB Workshop Part2
Rupy2012 ArangoDB Workshop Part2ArangoDB Database
 
Ako prepojiť aplikáciu s Elasticsearch
Ako prepojiť aplikáciu s ElasticsearchAko prepojiť aplikáciu s Elasticsearch
Ako prepojiť aplikáciu s Elasticsearchbart-sk
 
Real-time search in Drupal. Meet Elasticsearch
Real-time search in Drupal. Meet ElasticsearchReal-time search in Drupal. Meet Elasticsearch
Real-time search in Drupal. Meet ElasticsearchAlexei Gorobets
 
Working with WP_Query in WordPress
Working with WP_Query in WordPressWorking with WP_Query in WordPress
Working with WP_Query in WordPresstopher1kenobe
 
Chandra Prakash Thapa: Make a WordPress Multisite in 20 mins
Chandra Prakash Thapa: Make a WordPress Multisite in 20 minsChandra Prakash Thapa: Make a WordPress Multisite in 20 mins
Chandra Prakash Thapa: Make a WordPress Multisite in 20 minswpnepal
 
JSON REST API for WordPress
JSON REST API for WordPressJSON REST API for WordPress
JSON REST API for WordPressTaylor Lovett
 
Real-time search in Drupal with Elasticsearch @Moldcamp
Real-time search in Drupal with Elasticsearch @MoldcampReal-time search in Drupal with Elasticsearch @Moldcamp
Real-time search in Drupal with Elasticsearch @MoldcampAlexei Gorobets
 
Worcamp2012 make a wordpress multisite in 20mins
Worcamp2012 make a wordpress multisite in 20minsWorcamp2012 make a wordpress multisite in 20mins
Worcamp2012 make a wordpress multisite in 20minsChandra 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 2017The hitchhiker's guide to the Webpack - Sara Vieira - Codemotion Amsterdam 2017
The hitchhiker's guide to the Webpack - Sara Vieira - Codemotion Amsterdam 2017Codemotion
 
Ruby conf 2011, Create your own rails framework
Ruby conf 2011, Create your own rails frameworkRuby conf 2011, Create your own rails framework
Ruby conf 2011, Create your own rails frameworkPankaj Bhageria
 
Introduction to CouchDB
Introduction to CouchDBIntroduction to CouchDB
Introduction to CouchDBOpusVL
 
Scalable web application architecture
Scalable web application architectureScalable web application architecture
Scalable web application architecturepostrational
 
MuleSoft ESB Message Enricher
MuleSoft ESB Message Enricher MuleSoft ESB Message Enricher
MuleSoft ESB Message Enricher akashdprajapati
 
User Credential handling in Web Applications done right
User Credential handling in Web Applications done rightUser Credential handling in Web Applications done right
User Credential handling in Web Applications done righttladesignz
 

Tendances (20)

Modernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with ElasticsearchModernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with Elasticsearch
 
Memcache basics on google app engine
Memcache basics on google app engineMemcache basics on google app engine
Memcache basics on google app engine
 
The JSON REST API for WordPress
The JSON REST API for WordPressThe JSON REST API for WordPress
The JSON REST API for WordPress
 
Php basic for vit university
Php basic for vit universityPhp basic for vit university
Php basic for vit university
 
Express Presentation
Express PresentationExpress Presentation
Express Presentation
 
Rupy2012 ArangoDB Workshop Part2
Rupy2012 ArangoDB Workshop Part2Rupy2012 ArangoDB Workshop Part2
Rupy2012 ArangoDB Workshop Part2
 
Ako prepojiť aplikáciu s Elasticsearch
Ako prepojiť aplikáciu s ElasticsearchAko prepojiť aplikáciu s Elasticsearch
Ako prepojiť aplikáciu s Elasticsearch
 
Real-time search in Drupal. Meet Elasticsearch
Real-time search in Drupal. Meet ElasticsearchReal-time search in Drupal. Meet Elasticsearch
Real-time search in Drupal. Meet Elasticsearch
 
Working with WP_Query in WordPress
Working with WP_Query in WordPressWorking with WP_Query in WordPress
Working with WP_Query in WordPress
 
Chandra Prakash Thapa: Make a WordPress Multisite in 20 mins
Chandra Prakash Thapa: Make a WordPress Multisite in 20 minsChandra Prakash Thapa: Make a WordPress Multisite in 20 mins
Chandra Prakash Thapa: Make a WordPress Multisite in 20 mins
 
JSON REST API for WordPress
JSON REST API for WordPressJSON REST API for WordPress
JSON REST API for WordPress
 
Real-time search in Drupal with Elasticsearch @Moldcamp
Real-time search in Drupal with Elasticsearch @MoldcampReal-time search in Drupal with Elasticsearch @Moldcamp
Real-time search in Drupal with Elasticsearch @Moldcamp
 
Worcamp2012 make a wordpress multisite in 20mins
Worcamp2012 make a wordpress multisite in 20minsWorcamp2012 make a wordpress multisite in 20mins
Worcamp2012 make a wordpress multisite in 20mins
 
The hitchhiker's guide to the Webpack - Sara Vieira - Codemotion Amsterdam 2017
The hitchhiker's guide to the Webpack - Sara Vieira - Codemotion Amsterdam 2017The hitchhiker's guide to the Webpack - Sara Vieira - Codemotion Amsterdam 2017
The hitchhiker's guide to the Webpack - Sara Vieira - Codemotion Amsterdam 2017
 
Ruby conf 2011, Create your own rails framework
Ruby conf 2011, Create your own rails frameworkRuby conf 2011, Create your own rails framework
Ruby conf 2011, Create your own rails framework
 
Introduction to CouchDB
Introduction to CouchDBIntroduction to CouchDB
Introduction to CouchDB
 
Scalable web application architecture
Scalable web application architectureScalable web application architecture
Scalable web application architecture
 
MuleSoft ESB Message Enricher
MuleSoft ESB Message Enricher MuleSoft ESB Message Enricher
MuleSoft ESB Message Enricher
 
User Credential handling in Web Applications done right
User Credential handling in Web Applications done rightUser Credential handling in Web Applications done right
User Credential handling in Web Applications done right
 
Introduction to AJAX
Introduction to AJAXIntroduction to AJAX
Introduction to AJAX
 

En vedette

Final morris esri_nwgis_lidar
Final morris esri_nwgis_lidarFinal morris esri_nwgis_lidar
Final morris esri_nwgis_lidarEric Morris
 
Appendex e
Appendex eAppendex e
Appendex eswavicky
 
Chapter 4 Form Factors & Power Supplies
Chapter 4 Form Factors & Power SuppliesChapter 4 Form Factors & Power Supplies
Chapter 4 Form Factors & Power SuppliesPatty Ramsey
 
Chapter 4 Form Factors Power Supplies
Chapter 4 Form Factors Power SuppliesChapter 4 Form Factors Power Supplies
Chapter 4 Form Factors Power SuppliesPatty Ramsey
 
Introduction to PHP - SDPHP
Introduction to PHP - SDPHPIntroduction to PHP - SDPHP
Introduction to PHP - SDPHPEric Johnson
 
LiDAR Aided Decision Making
LiDAR Aided Decision MakingLiDAR Aided Decision Making
LiDAR Aided Decision MakingLidar Blog
 
WE1.L10 - GRACE Applications to Regional Hydrology and Water Resources
WE1.L10 - GRACE Applications to Regional Hydrology and Water ResourcesWE1.L10 - GRACE Applications to Regional Hydrology and Water Resources
WE1.L10 - GRACE Applications to Regional Hydrology and Water Resourcesgrssieee
 
final emoji-board EMAIL ME NOWSWAG11
final emoji-board EMAIL ME NOWSWAG11final emoji-board EMAIL ME NOWSWAG11
final emoji-board EMAIL ME NOWSWAG11Joe Humphreys
 
Appendex b
Appendex bAppendex b
Appendex bswavicky
 
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 ExtensionPreparing LiDAR for Use in ArcGIS 10.1 with the Data Interoperability Extension
Preparing LiDAR for Use in ArcGIS 10.1 with the Data Interoperability ExtensionSafe Software
 
Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)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 CentereMail 101 (2) Class for Selfhelp Virtual Senior Center
eMail 101 (2) Class for Selfhelp Virtual Senior CenterSnowSugar Video
 
5 Accessing Information Resources
5 Accessing Information Resources5 Accessing Information Resources
5 Accessing Information ResourcesPatty Ramsey
 
PHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet SolutionPHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet SolutionMazenetsolution
 
Ch5(ms access with php)
Ch5(ms access with php)Ch5(ms access with php)
Ch5(ms access with php)Chhom Karath
 
Appendex g
Appendex gAppendex g
Appendex gswavicky
 
PHP 5.3 Part 1 - Introduction to PHP 5.3
PHP 5.3 Part 1 - Introduction to PHP 5.3PHP 5.3 Part 1 - Introduction to PHP 5.3
PHP 5.3 Part 1 - Introduction to PHP 5.3melechi
 
Survey Grade LiDAR Technologies for Transportation Engineering
Survey Grade LiDAR Technologies for Transportation EngineeringSurvey Grade LiDAR Technologies for Transportation Engineering
Survey Grade LiDAR Technologies for Transportation EngineeringQuantum Spatial
 
Setting up a gmail account
Setting up a gmail accountSetting up a gmail account
Setting up a gmail accountkeelyswitzer
 

En vedette (20)

Final morris esri_nwgis_lidar
Final morris esri_nwgis_lidarFinal morris esri_nwgis_lidar
Final morris esri_nwgis_lidar
 
Appendex e
Appendex eAppendex e
Appendex e
 
Chapter 4 Form Factors & Power Supplies
Chapter 4 Form Factors & Power SuppliesChapter 4 Form Factors & Power Supplies
Chapter 4 Form Factors & Power Supplies
 
Chapter 4 Form Factors Power Supplies
Chapter 4 Form Factors Power SuppliesChapter 4 Form Factors Power Supplies
Chapter 4 Form Factors Power Supplies
 
Introduction to PHP - SDPHP
Introduction to PHP - SDPHPIntroduction to PHP - SDPHP
Introduction to PHP - SDPHP
 
Ch07
Ch07Ch07
Ch07
 
LiDAR Aided Decision Making
LiDAR Aided Decision MakingLiDAR Aided Decision Making
LiDAR Aided Decision Making
 
WE1.L10 - GRACE Applications to Regional Hydrology and Water Resources
WE1.L10 - GRACE Applications to Regional Hydrology and Water ResourcesWE1.L10 - GRACE Applications to Regional Hydrology and Water Resources
WE1.L10 - GRACE Applications to Regional Hydrology and Water Resources
 
final emoji-board EMAIL ME NOWSWAG11
final emoji-board EMAIL ME NOWSWAG11final emoji-board EMAIL ME NOWSWAG11
final emoji-board EMAIL ME NOWSWAG11
 
Appendex b
Appendex bAppendex b
Appendex b
 
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 ExtensionPreparing 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
 
Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)
 
eMail 101 (2) Class for Selfhelp Virtual Senior Center
eMail 101 (2) Class for Selfhelp Virtual Senior CentereMail 101 (2) Class for Selfhelp Virtual Senior Center
eMail 101 (2) Class for Selfhelp Virtual Senior Center
 
5 Accessing Information Resources
5 Accessing Information Resources5 Accessing Information Resources
5 Accessing Information Resources
 
PHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet SolutionPHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet Solution
 
Ch5(ms access with php)
Ch5(ms access with php)Ch5(ms access with php)
Ch5(ms access with php)
 
Appendex g
Appendex gAppendex g
Appendex g
 
PHP 5.3 Part 1 - Introduction to PHP 5.3
PHP 5.3 Part 1 - Introduction to PHP 5.3PHP 5.3 Part 1 - Introduction to PHP 5.3
PHP 5.3 Part 1 - Introduction to PHP 5.3
 
Survey Grade LiDAR Technologies for Transportation Engineering
Survey Grade LiDAR Technologies for Transportation EngineeringSurvey Grade LiDAR Technologies for Transportation Engineering
Survey Grade LiDAR Technologies for Transportation Engineering
 
Setting up a gmail account
Setting up a gmail accountSetting up a gmail account
Setting up a gmail account
 

Similaire à Ch7(publishing my sql data on the web)

PHP and MySQL.pptx
PHP and MySQL.pptxPHP and MySQL.pptx
PHP and MySQL.pptxnatesanp1234
 
Scaling WordPress On A Small Budget
Scaling WordPress On A Small BudgetScaling WordPress On A Small Budget
Scaling WordPress On A Small BudgetBrecht Ryckaert
 
HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.jssouridatta
 
Intro to php
Intro to phpIntro to php
Intro to phpSp Singh
 
PythonDatabaseAPI -Presentation for Database
PythonDatabaseAPI -Presentation for DatabasePythonDatabaseAPI -Presentation for Database
PythonDatabaseAPI -Presentation for Databasedharawagh9999
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5Bukhori Aqid
 
Introduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to ChefIntroduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to ChefNathen Harvey
 
Boost your website by running PHP on Nginx
Boost your website by running PHP on NginxBoost your website by running PHP on Nginx
Boost your website by running PHP on NginxHarald Zeitlhofer
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsAdrien Guéret
 
Php &amp; my sql - how do pdo, mysq-li, and x devapi do what they do
Php &amp; my sql  - how do pdo, mysq-li, and x devapi do what they doPhp &amp; my sql  - how do pdo, mysq-li, and x devapi do what they do
Php &amp; my sql - how do pdo, mysq-li, and x devapi do what they doDave Stokes
 

Similaire à Ch7(publishing my sql data on the web) (20)

Phphacku iitd
Phphacku iitdPhphacku iitd
Phphacku iitd
 
PHP and MySQL.pptx
PHP and MySQL.pptxPHP and MySQL.pptx
PHP and MySQL.pptx
 
Scaling WordPress On A Small Budget
Scaling WordPress On A Small BudgetScaling WordPress On A Small Budget
Scaling WordPress On A Small Budget
 
Top ten-list
Top ten-listTop ten-list
Top ten-list
 
HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.js
 
Intro to php
Intro to phpIntro to php
Intro to php
 
PythonDatabaseAPI -Presentation for Database
PythonDatabaseAPI -Presentation for DatabasePythonDatabaseAPI -Presentation for Database
PythonDatabaseAPI -Presentation for Database
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5
 
Php summary
Php summaryPhp summary
Php summary
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
Owasp Top 10 A1: Injection
Owasp Top 10 A1: InjectionOwasp Top 10 A1: Injection
Owasp Top 10 A1: Injection
 
Introduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to ChefIntroduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to Chef
 
phptut4
phptut4phptut4
phptut4
 
phptut4
phptut4phptut4
phptut4
 
Boost your website by running PHP on Nginx
Boost your website by running PHP on NginxBoost your website by running PHP on Nginx
Boost your website by running PHP on Nginx
 
Introduction to Chef
Introduction to ChefIntroduction to Chef
Introduction to Chef
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
MySQL with PHP
MySQL with PHPMySQL with PHP
MySQL with PHP
 
Php &amp; my sql - how do pdo, mysq-li, and x devapi do what they do
Php &amp; my sql  - how do pdo, mysq-li, and x devapi do what they doPhp &amp; my sql  - how do pdo, mysq-li, and x devapi do what they do
Php &amp; my sql - how do pdo, mysq-li, and x devapi do what they do
 
Python with MySql.pptx
Python with MySql.pptxPython with MySql.pptx
Python with MySql.pptx
 

Plus de Chhom Karath

Plus de Chhom Karath (20)

set1.pdf
set1.pdfset1.pdf
set1.pdf
 
Set1.pptx
Set1.pptxSet1.pptx
Set1.pptx
 
orthodontic patient education.pdf
orthodontic patient education.pdforthodontic patient education.pdf
orthodontic patient education.pdf
 
New ton 3.pdf
New ton 3.pdfNew ton 3.pdf
New ton 3.pdf
 
ច្បាប់ញូតុនទី៣.pptx
ច្បាប់ញូតុនទី៣.pptxច្បាប់ញូតុនទី៣.pptx
ច្បាប់ញូតុនទី៣.pptx
 
Control tipping.pptx
Control tipping.pptxControl tipping.pptx
Control tipping.pptx
 
Bulbous loop.pptx
Bulbous loop.pptxBulbous loop.pptx
Bulbous loop.pptx
 
brush teeth.pptx
brush teeth.pptxbrush teeth.pptx
brush teeth.pptx
 
bracket size.pptx
bracket size.pptxbracket size.pptx
bracket size.pptx
 
arch form KORI copy.pptx
arch form KORI copy.pptxarch form KORI copy.pptx
arch form KORI copy.pptx
 
Bracket size
Bracket sizeBracket size
Bracket size
 
Couple
CoupleCouple
Couple
 
ច្បាប់ញូតុនទី៣
ច្បាប់ញូតុនទី៣ច្បាប់ញូតុនទី៣
ច្បាប់ញូតុនទី៣
 
Game1
Game1Game1
Game1
 
Shoe horn loop
Shoe horn loopShoe horn loop
Shoe horn loop
 
Opus loop
Opus loopOpus loop
Opus loop
 
V bend
V bendV bend
V bend
 
Closing loop
Closing loopClosing loop
Closing loop
 
Maxillary arch form
Maxillary arch formMaxillary arch form
Maxillary arch form
 
Front face analysis
Front face analysisFront face analysis
Front face analysis
 

Dernier

So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Nikki Chapple
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsYoss Cohen
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sectoritnewsafrica
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 

Dernier (20)

So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platforms
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 

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>'); }

Notes de l'éditeur

  1. <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>
  2. <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; ?>