SlideShare uma empresa Scribd logo
1 de 10
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)

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque

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
 

Destaque (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
 

Semelhante a 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
 

Semelhante a 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
 

Mais de Chhom Karath

Mais 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
 

Último

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Último (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

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

Notas do Editor

  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; ?>