SlideShare a Scribd company logo
Overview Download MYSQL GUI What is a database, creating data Creating a database in MySQL SQL scripts Connecting to a database in PHP Viewing records
Download and install mysql gui Download from  here http://dev.mysql.com/downloads/gui-tools/5.0.html
What is a database About.com http://databases.about.com/od/specificproducts/a/whatisadatabase.htm Wikipedia http://en.wikipedia.org/wiki/Database Tutorial  on a database http://www.htmlgoodies.com/beyond/reference/article.php/3472691 Mysql tutorial http://www.w3schools.com/php/php_mysql_intro.asp
What is a data kildare Male Couper Tristan 01/01/1987 kildare Male Connolly Aidan kildare Male Clarke Richard 13/07/1980 meath Female Griffin Sheila 11/11/1977 meath Male Meagher David  01/05/1978 dublin Male O'Sullivan John 31/05/1972 dublin Male Murphy John date of birth County Gender Surname First Name
What is a database Address table kildare Male Couper Tristan 7 01/01/1987 kildare Male Connolly Aidan 6 kildare Male Clarke Richard 5 13/07/1980 meath Female Griffin Sheila 4 11/11/1977 meath Male Meagher David  3 01/05/1978 dublin Male O'Sullivan John 2 31/05/1972 dublin Male Murphy John 1 date of birth County Gender Surname First Name id
What are data types Address table kildare Male Couper Tristan 7 01/01/1987 kildare Male Connolly Aidan 6 kildare Male Clarke Richard 5 13/07/1980 meath Female Griffin Sheila 4 11/11/1977 meath Male Meagher David  3 01/05/1978 dublin Male O'Sullivan John 2 31/05/1972 dublin Male Murphy John 1 date varchar varchar varchar varchar integer
What is data normalization Address table kildare Male Couper Tristan 7 01/01/1987 kildare Male Connolly Aidan 6 kildare Male Clarke Richard 5 13/07/1980 meath Female Griffin Sheila 4 11/11/1977 meath Male Meagher David  3 01/05/1978 dublin Male O'Sullivan John 2 31/05/1972 dublin Male Murphy John 1 date of birth County Gender Surname First Name id
What is data normalization Address table county table kildare Male Couper Tristan 7 01/01/1987 kildare Male Connolly Aidan 6 kildare Male Clarke Richard 5 13/07/1980 meath Female Griffin Sheila 4 11/11/1977 meath Male Meagher David  3 01/05/1978 dublin Male O'Sullivan John 2 31/05/1972 dublin Male Murphy John 1 date of birth County Gender Surname First Name id meath kildare dublin County
What is data normalization Address table county table 2 Male Couper Tristan 7 01/01/1987 2 Male Connolly Aidan 6 2 Male Clarke Richard 5 13/07/1980 3 Female Griffin Sheila 4 11/11/1977 3 Male Meagher David  3 01/05/1978 1 Male O'Sullivan John 2 31/05/1972 1 Male Murphy John 1 date of birth CId Gender Surname First Name id meath 3 kildare 2 dublin 1 County Cid
Connecting to MySQL Load up MYSQL ADMIN Server is  localhost Username is  root Port is  3306
Creating a database in MySQL Click on catalogues in the list And right click inside schemas to create a new database
Creating a table in MySQL Create a new table called contacts with the following information ID is always a primary key Should be set  to autoincrement
Adding data in MySQL Right click the new table and choose EDIT TABLE DATA, this opens the table editor
Adding data in MySQL To enter data click the  edit  button and enter details into the fields. The ID key should autoincrement
MySQL Query to select data SELECT * FROM contacts; SELECT CFName FROM contacts; SELECT * FROM contacts WHERE id = 4; SELECT * FROM contacts ORDER BY CFName; Operator Description = Equal != Not equal > Greater than < Less than >= Greater than or equal <= Less than or equal BETWEEN Between an inclusive range LIKE Search for a pattern – use % for wild card characters - use single quotes for strings, no quotes for numbers
MySQL Query to insert data INSERT INTO contacts (CFName, CSName, CAge) values ('Big' ,'tom', 23);
MySQL Query to update data The SQL statement UPDATE is used to change the value in a table. For example to change  CFName  from  big  to  small   UPDATE contacts SET CFName = 'small' WHERE CFName = 'big'; Note:  SQL statements are not case sensitive, e.g.  WHERE  is the same as  where .
MySQL Query to Delete data The DELETE statement deletes rows from a table that satisfy the condition given by the WHERE clause.  For example to delete a record from  contact  table where  id  equals 1 DELETE FROM contacts WHERE CId = 1;
Connecting to a Database through PHP Opening a connection to MySQL from PHP is easy Just use the  mysql_connect()  function like this  mysql_connect(servername,username,password);
Connecting to a Database through PHP <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $conn  = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql:'. mysql_error()); $dbname  = ' dynamicweb '; mysql_select_db($dbname); ?>
Connecting to a Database through PHP It's a common practice to place the routine of opening a database connection in a separate file. Then every time you want to open a connection just include the file. Usually the host, user, password and database name are also separated in a configuration file.  <?php // This is an example of dbconfig.php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'password'; $dbname = 'myDBname'; ?>  <?php // This is an example dbopen.php $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); ?>
Connecting to a Database through PHP <?php include 'DBconfig.php'; include 'DBopen.php'; // ... do something like insert or select, etc ?>
Closing a Database through PHP <?php // an example of  closedb.php // it does nothing but closing // a mysql database connection mysql_close($conn); ?> <?php include 'config.php'; include 'opendb.php'; // ... do something like // insert or select, etc include 'dbclose.php'; ?>
Listing data in a database using PHP To get PHP to execute MySQL statements we must use the  mysql_query()  function. This function is used to send a  query  or  command  to a MySQL connection. e.g.: Using PHP you can run a MySQL  SELECT  query to fetch the data out of the database.  You have several options in fetching information from MySQL. PHP provide several functions for this.  The first one is  mysql_fetch_array()   which fetches a result row as an  associative array , a  numeric   array , or both.  Below is an example of fetching data from MySQL, the table  contacts  has three columns; cF name , c Lname  and c Age .
Listing data in a database using PHP <?php include 'DBconfig.php'; include 'DBopen.php'; $query = &quot;SELECT cFname, cLname, cAge FROM contacts&quot;; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ echo &quot;First Name: $row[Fname] <br>&quot;. &quot;Second Name: $row[Lname] <br>&quot;. &quot;Age: $row[age] <br><br>&quot;; } include 'DBclose.php'; ?>
Insert Data from a Form into a Database  <html>  <body> <form action=&quot; insert.php &quot; method=&quot;post&quot;>  Firstname: <input type=&quot;text&quot; name=&quot;firstname&quot; /> Lastname: <input type=&quot;text&quot; name=&quot;lastname&quot; />  Age: <input type=&quot;text&quot; name=&quot;age&quot; />  <input type=&quot;submit&quot; />  </form> </body>  </html>
Insert Data from a Form into a Database <?php //php file “ insert.php ” $con = mysql_connect(&quot;localhost&quot;,&quot;peter&quot;,&quot;abc123&quot;);  if (!$con)  { die('Could not connect: ' . mysql_error()); } mysql_select_db(&quot;my_db&quot;, $con); $sql=&quot;INSERT INTO  table_name  (FirstName, LastName, Age) VALUES  ('$_POST[firstname]','$_POST[lastname]','$_POST[age]')&quot;; if (!mysql_query($sql,$con))  { die('Error: ' . mysql_error()); }  echo &quot;1 record added&quot;; mysql_close($con)  ?>
Select Data From a Database Table with php  <?php  $con = mysql_connect(&quot;localhost&quot;,&quot;peter&quot;,&quot;abc123&quot;);  if (!$con)  { die('Could not connect: ' . mysql_error()); } mysql_select_db(&quot;my_db&quot;, $con); $result = mysql_query(&quot;SELECT * FROM  table_name &quot;); while($row = mysql_fetch_array($result)) {  echo $row['FirstName'] . &quot; &quot; . $row['LastName'];  echo &quot;<br />&quot;;  } mysql_close($con);  ?>
Display the Result in an HTML Table  <?php  $con = mysql_connect(&quot;localhost&quot;,&quot;peter&quot;,&quot;abc123&quot;);  if (!$con)  { die('Could not connect: ' . mysql_error()); } mysql_select_db(&quot;my_db&quot;, $con);  $result = mysql_query(&quot;SELECT * FROM  table_name &quot;);  echo  &quot; <table border='1'>   < tr> <th>Firstname</th><th>Lastname</th></tr>&quot;; while($row = mysql_fetch_assoc($result)) {  echo &quot;<tr>&quot;;  echo &quot;<td>&quot; . $row['FirstName'] . &quot;</td>&quot;;  echo &quot;<td>&quot; . $row['LastName'] . &quot;</td>&quot;;  echo &quot;</tr>&quot;;  }  echo &quot;</table>&quot;; mysql_close($con);  ?>

More Related Content

PDF
Coming to Terms with GraphQL
PPTX
xsvutils overview
PDF
Cowboy development with Django
PDF
FLOW3, Extbase & Fluid cook book
PPT
PHP file
PDF
File system
PDF
GoogleService
PDF
Semalt: 3 Steps To PHP Web Page Scraping Web
Coming to Terms with GraphQL
xsvutils overview
Cowboy development with Django
FLOW3, Extbase & Fluid cook book
PHP file
File system
GoogleService
Semalt: 3 Steps To PHP Web Page Scraping Web

What's hot (18)

PDF
Advanced MongoDB Aggregation Pipelines
PDF
Mengembalikan data yang terhapus atau rusak pada hardisk menggunakan ubuntu
PDF
Rooted 2010 ppp
PPT
Hi5 Opensocial Code Lab Presentation
DOCX
Php mysql connectivity
PPTX
Android Lab Test : Reading the foot file list (english)
PDF
Sqlite perl
PDF
Idoc script beginner guide
PDF
The Django Web Framework (EuroPython 2006)
DOCX
Database adapter
PPT
Database presentation
PDF
Bigdive 2014 - RDF, principles and case studies
PPTX
File upload for the 21st century
PPT
Working with LifeDesks
KEY
What Is Seo How Search Engine Works
PDF
13- Learn CSS Fundamentals / Specificity
Advanced MongoDB Aggregation Pipelines
Mengembalikan data yang terhapus atau rusak pada hardisk menggunakan ubuntu
Rooted 2010 ppp
Hi5 Opensocial Code Lab Presentation
Php mysql connectivity
Android Lab Test : Reading the foot file list (english)
Sqlite perl
Idoc script beginner guide
The Django Web Framework (EuroPython 2006)
Database adapter
Database presentation
Bigdive 2014 - RDF, principles and case studies
File upload for the 21st century
Working with LifeDesks
What Is Seo How Search Engine Works
13- Learn CSS Fundamentals / Specificity
Ad

Viewers also liked (7)

PDF
Transact sql data definition language - ddl- reference
PPTX
Data definition language postgreSQL
PPT
1. Introduction to DBMS
PPT
MYSQL.ppt
PPT
MySql slides (ppt)
PDF
CBSE XII Database Concepts And MySQL Presentation
PDF
LinkedIn SlideShare: Knowledge, Well-Presented
Transact sql data definition language - ddl- reference
Data definition language postgreSQL
1. Introduction to DBMS
MYSQL.ppt
MySql slides (ppt)
CBSE XII Database Concepts And MySQL Presentation
LinkedIn SlideShare: Knowledge, Well-Presented
Ad

Similar to Introtodatabase 1 (20)

PPTX
Learn PHP Lacture2
PPTX
Mysql
PPT
SQL -PHP Tutorial
PPTX
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering College
PPTX
UNIT V (5).pptx
PDF
Php 2
PPSX
DIWE - Working with MySQL Databases
PPTX
CHAPTER six DataBase Driven Websites.pptx
PPT
Short Intro to PHP and MySQL
PPTX
Class 8 - Database Programming
PPT
My sql with querys
PDF
MySQL for beginners
PPT
PPT
MySQL Database System Hiep Dinh
PPT
mysqlHiep.ppt
ODP
PPT
php databse handling
PPT
Migrating from PHP 4 to PHP 5
PPT
Lecture 15 - MySQL- PHP 1.ppt
Learn PHP Lacture2
Mysql
SQL -PHP Tutorial
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering College
UNIT V (5).pptx
Php 2
DIWE - Working with MySQL Databases
CHAPTER six DataBase Driven Websites.pptx
Short Intro to PHP and MySQL
Class 8 - Database Programming
My sql with querys
MySQL for beginners
MySQL Database System Hiep Dinh
mysqlHiep.ppt
php databse handling
Migrating from PHP 4 to PHP 5
Lecture 15 - MySQL- PHP 1.ppt

More from Digital Insights - Digital Marketing Agency (20)

PPT
Diploma-GCD-ContentMarketing-Personas-Week2
PPT
DigitalInsights-DigitalMarketingStrategy&Planning
PPT
PPT
DBS-Week2-DigitalStrategySession
PPT
GCD-Measurement&Analytics-Week11
PPT
DBS-Week1-Introduction&OverviewDigitalMarketing
PPT
DCEB-DigitalStrategySession-Jan24th
PPTX
PPT
PPTX
Week12-DBS-ReviewAndPlanningSession
PPT
GCD-Week5-Facebook-LinkedIn-Ads
PPT
DBS-Week11-Measurement&Analyics
PPT
PPTX
DBS-Week10-EcommSites&SalesFunnells
PPT
GCD-Week5-SocialMediaPlatforms
PPT
DBS-Week3-B2C&B2B-ContentMarketing-Session
PPTX
DBS-Week9-Wordpress-Session
Diploma-GCD-ContentMarketing-Personas-Week2
DigitalInsights-DigitalMarketingStrategy&Planning
DBS-Week2-DigitalStrategySession
GCD-Measurement&Analytics-Week11
DBS-Week1-Introduction&OverviewDigitalMarketing
DCEB-DigitalStrategySession-Jan24th
Week12-DBS-ReviewAndPlanningSession
GCD-Week5-Facebook-LinkedIn-Ads
DBS-Week11-Measurement&Analyics
DBS-Week10-EcommSites&SalesFunnells
GCD-Week5-SocialMediaPlatforms
DBS-Week3-B2C&B2B-ContentMarketing-Session
DBS-Week9-Wordpress-Session

Recently uploaded (20)

PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Approach and Philosophy of On baking technology
PPTX
Cloud computing and distributed systems.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PPT
Teaching material agriculture food technology
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
KodekX | Application Modernization Development
Review of recent advances in non-invasive hemoglobin estimation
Unlocking AI with Model Context Protocol (MCP)
Approach and Philosophy of On baking technology
Cloud computing and distributed systems.
Dropbox Q2 2025 Financial Results & Investor Presentation
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
cuic standard and advanced reporting.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
The Rise and Fall of 3GPP – Time for a Sabbatical?
“AI and Expert System Decision Support & Business Intelligence Systems”
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Electronic commerce courselecture one. Pdf
Encapsulation_ Review paper, used for researhc scholars
Teaching material agriculture food technology
Advanced methodologies resolving dimensionality complications for autism neur...
The AUB Centre for AI in Media Proposal.docx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
KodekX | Application Modernization Development

Introtodatabase 1

  • 1. Overview Download MYSQL GUI What is a database, creating data Creating a database in MySQL SQL scripts Connecting to a database in PHP Viewing records
  • 2. Download and install mysql gui Download from here http://dev.mysql.com/downloads/gui-tools/5.0.html
  • 3. What is a database About.com http://databases.about.com/od/specificproducts/a/whatisadatabase.htm Wikipedia http://en.wikipedia.org/wiki/Database Tutorial on a database http://www.htmlgoodies.com/beyond/reference/article.php/3472691 Mysql tutorial http://www.w3schools.com/php/php_mysql_intro.asp
  • 4. What is a data kildare Male Couper Tristan 01/01/1987 kildare Male Connolly Aidan kildare Male Clarke Richard 13/07/1980 meath Female Griffin Sheila 11/11/1977 meath Male Meagher David 01/05/1978 dublin Male O'Sullivan John 31/05/1972 dublin Male Murphy John date of birth County Gender Surname First Name
  • 5. What is a database Address table kildare Male Couper Tristan 7 01/01/1987 kildare Male Connolly Aidan 6 kildare Male Clarke Richard 5 13/07/1980 meath Female Griffin Sheila 4 11/11/1977 meath Male Meagher David 3 01/05/1978 dublin Male O'Sullivan John 2 31/05/1972 dublin Male Murphy John 1 date of birth County Gender Surname First Name id
  • 6. What are data types Address table kildare Male Couper Tristan 7 01/01/1987 kildare Male Connolly Aidan 6 kildare Male Clarke Richard 5 13/07/1980 meath Female Griffin Sheila 4 11/11/1977 meath Male Meagher David 3 01/05/1978 dublin Male O'Sullivan John 2 31/05/1972 dublin Male Murphy John 1 date varchar varchar varchar varchar integer
  • 7. What is data normalization Address table kildare Male Couper Tristan 7 01/01/1987 kildare Male Connolly Aidan 6 kildare Male Clarke Richard 5 13/07/1980 meath Female Griffin Sheila 4 11/11/1977 meath Male Meagher David 3 01/05/1978 dublin Male O'Sullivan John 2 31/05/1972 dublin Male Murphy John 1 date of birth County Gender Surname First Name id
  • 8. What is data normalization Address table county table kildare Male Couper Tristan 7 01/01/1987 kildare Male Connolly Aidan 6 kildare Male Clarke Richard 5 13/07/1980 meath Female Griffin Sheila 4 11/11/1977 meath Male Meagher David 3 01/05/1978 dublin Male O'Sullivan John 2 31/05/1972 dublin Male Murphy John 1 date of birth County Gender Surname First Name id meath kildare dublin County
  • 9. What is data normalization Address table county table 2 Male Couper Tristan 7 01/01/1987 2 Male Connolly Aidan 6 2 Male Clarke Richard 5 13/07/1980 3 Female Griffin Sheila 4 11/11/1977 3 Male Meagher David 3 01/05/1978 1 Male O'Sullivan John 2 31/05/1972 1 Male Murphy John 1 date of birth CId Gender Surname First Name id meath 3 kildare 2 dublin 1 County Cid
  • 10. Connecting to MySQL Load up MYSQL ADMIN Server is localhost Username is root Port is 3306
  • 11. Creating a database in MySQL Click on catalogues in the list And right click inside schemas to create a new database
  • 12. Creating a table in MySQL Create a new table called contacts with the following information ID is always a primary key Should be set to autoincrement
  • 13. Adding data in MySQL Right click the new table and choose EDIT TABLE DATA, this opens the table editor
  • 14. Adding data in MySQL To enter data click the edit button and enter details into the fields. The ID key should autoincrement
  • 15. MySQL Query to select data SELECT * FROM contacts; SELECT CFName FROM contacts; SELECT * FROM contacts WHERE id = 4; SELECT * FROM contacts ORDER BY CFName; Operator Description = Equal != Not equal > Greater than < Less than >= Greater than or equal <= Less than or equal BETWEEN Between an inclusive range LIKE Search for a pattern – use % for wild card characters - use single quotes for strings, no quotes for numbers
  • 16. MySQL Query to insert data INSERT INTO contacts (CFName, CSName, CAge) values ('Big' ,'tom', 23);
  • 17. MySQL Query to update data The SQL statement UPDATE is used to change the value in a table. For example to change CFName from big to small UPDATE contacts SET CFName = 'small' WHERE CFName = 'big'; Note: SQL statements are not case sensitive, e.g. WHERE is the same as where .
  • 18. MySQL Query to Delete data The DELETE statement deletes rows from a table that satisfy the condition given by the WHERE clause. For example to delete a record from contact table where id equals 1 DELETE FROM contacts WHERE CId = 1;
  • 19. Connecting to a Database through PHP Opening a connection to MySQL from PHP is easy Just use the mysql_connect() function like this mysql_connect(servername,username,password);
  • 20. Connecting to a Database through PHP <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql:'. mysql_error()); $dbname = ' dynamicweb '; mysql_select_db($dbname); ?>
  • 21. Connecting to a Database through PHP It's a common practice to place the routine of opening a database connection in a separate file. Then every time you want to open a connection just include the file. Usually the host, user, password and database name are also separated in a configuration file. <?php // This is an example of dbconfig.php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'password'; $dbname = 'myDBname'; ?> <?php // This is an example dbopen.php $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); ?>
  • 22. Connecting to a Database through PHP <?php include 'DBconfig.php'; include 'DBopen.php'; // ... do something like insert or select, etc ?>
  • 23. Closing a Database through PHP <?php // an example of closedb.php // it does nothing but closing // a mysql database connection mysql_close($conn); ?> <?php include 'config.php'; include 'opendb.php'; // ... do something like // insert or select, etc include 'dbclose.php'; ?>
  • 24. Listing data in a database using PHP To get PHP to execute MySQL statements we must use the mysql_query() function. This function is used to send a query or command to a MySQL connection. e.g.: Using PHP you can run a MySQL SELECT query to fetch the data out of the database. You have several options in fetching information from MySQL. PHP provide several functions for this. The first one is mysql_fetch_array() which fetches a result row as an associative array , a numeric array , or both. Below is an example of fetching data from MySQL, the table contacts has three columns; cF name , c Lname and c Age .
  • 25. Listing data in a database using PHP <?php include 'DBconfig.php'; include 'DBopen.php'; $query = &quot;SELECT cFname, cLname, cAge FROM contacts&quot;; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ echo &quot;First Name: $row[Fname] <br>&quot;. &quot;Second Name: $row[Lname] <br>&quot;. &quot;Age: $row[age] <br><br>&quot;; } include 'DBclose.php'; ?>
  • 26. Insert Data from a Form into a Database <html> <body> <form action=&quot; insert.php &quot; method=&quot;post&quot;> Firstname: <input type=&quot;text&quot; name=&quot;firstname&quot; /> Lastname: <input type=&quot;text&quot; name=&quot;lastname&quot; /> Age: <input type=&quot;text&quot; name=&quot;age&quot; /> <input type=&quot;submit&quot; /> </form> </body> </html>
  • 27. Insert Data from a Form into a Database <?php //php file “ insert.php ” $con = mysql_connect(&quot;localhost&quot;,&quot;peter&quot;,&quot;abc123&quot;); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db(&quot;my_db&quot;, $con); $sql=&quot;INSERT INTO table_name (FirstName, LastName, Age) VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[age]')&quot;; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo &quot;1 record added&quot;; mysql_close($con) ?>
  • 28. Select Data From a Database Table with php <?php $con = mysql_connect(&quot;localhost&quot;,&quot;peter&quot;,&quot;abc123&quot;); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db(&quot;my_db&quot;, $con); $result = mysql_query(&quot;SELECT * FROM table_name &quot;); while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . &quot; &quot; . $row['LastName']; echo &quot;<br />&quot;; } mysql_close($con); ?>
  • 29. Display the Result in an HTML Table <?php $con = mysql_connect(&quot;localhost&quot;,&quot;peter&quot;,&quot;abc123&quot;); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db(&quot;my_db&quot;, $con); $result = mysql_query(&quot;SELECT * FROM table_name &quot;); echo &quot; <table border='1'> < tr> <th>Firstname</th><th>Lastname</th></tr>&quot;; while($row = mysql_fetch_assoc($result)) { echo &quot;<tr>&quot;; echo &quot;<td>&quot; . $row['FirstName'] . &quot;</td>&quot;; echo &quot;<td>&quot; . $row['LastName'] . &quot;</td>&quot;; echo &quot;</tr>&quot;; } echo &quot;</table>&quot;; mysql_close($con); ?>