SlideShare a Scribd company logo
PHP Mysql connectivity
Use the mysql_connect( ) functiontoestablishedconnectiontothe MySQLserver.To accessthe
database functionalitywe have tomake a connectiontodatabase usingPhp.mysql_connect() function
isusedto establishthe connectiontomysql server.
Four argumentsneedtobe passedtomysql_connect() function.
Hostname : if you are working on local system , you can use localhost or you can also
provide ip address or server name.
username : if there is a existing user , you can provide username. default username is
'root'.
password : by default password is blank or null.
dbname : it is a optional field . it is basically a name of the database that need to be
connected.
mysql_connect(host, username, password, dbname);
Parameter Description
host(Server name) Either a host name(server name) or an IP address
username The MySQL user name
password The password to log in with
dbname Optional. The database to be used when performing queries
Note : There are more available parameters, but the ones listed above are the most
important. In the following example we store the connection in a variable ($con) for later
use in the script
<?php
// Create connection
$con=mysql_connect("localhost","root","") or die(mysql_error());
?>
Here localhost is server name. root is MySQL default user name. default password is blank and
database name is my_db. mysql_error( ) function provides mysql connectivity error message.
MySQL Close Connection
<?php
// Create connection
$con=mysql_connect("localhost","root","","my_db") or die(mysql_error());
//code to be executed...
// Close connection
mysql_close($con);
?>
after work with the database is done we have to close the connection using mysql_close()
function in which the connection to the database is passed.
Mysqli PHP Connectivity
How to connect PHP through mysqli. Create a registration form with 4 four fields
name,email id, mobile number and address. Fill all the fields click on save data submit
button to save your data inside "users" table using mysqli prepared statements insert.
To display all the values from "users" table click on disp data button it will display the
values using mysqli prepared statements select.
Create Database and Table
Database name:demo
Table:user
PHP Script(PHP mysqli connection )
<?php
//mysqli connectivity
$connect= new mysqli("localhost","root","","demo") or die("ERROR:could not
connect to the database!!!!");
extract($_POST);
if(isset($save))
{
$query="insert into users values('','$n','$e','$m','$add')";
if($connect->query($query))
{
echo 'congrates!! data saved';
}
else
{
echo 'data not saved '.$connect->error;
}
}
//display data
if(isset($disp))
{
$query="select * from users";
$result=$connect->query($query);
echo "<table border=1>";
echo "<tr><th>Name</th><th>Email</th><th>Mobile<
/th><th>Address</th></tr>";
while($row=$result->fetch_array())
{
echo "<tr>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['email']."</td>";
echo "<td>".$row['mobile']."</td>";
echo "<td>".$row['address']."</td>";
echo "</tr>";
}
echo "</table>";
}
?>
HTML Form
<style>
input,textarea{width:200px}
input[type=submit]{width:100px}
</style>
<form method="post">
<table width="218" border="0">
<tr>
<td width="208"><input type="text" name="n" placeholder="Enter your
name"/></td>
</tr>
<tr>
<td><input type="text" name="e" placeholder="Enter your email"/></td>
</tr>
<tr>
<td><input type="text" name="m" placeholder="Enter your mobile"/></td>
</tr>
<tr>
<td><textarea name="add" placeholder="Enter your address"></textarea></td>
</tr>
<tr>
<td>
<input type="submit" name="save" value="Save Data"/>
<input type="submit" name="disp" value="Display Data"/>
</td>
</tr>
</table>
</form>
Php mysql connectivity

More Related Content

What's hot (18)

MySQLi
MySQLiMySQLi
MySQLi
Ankit Bahuguna
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
Computer Hardware & Trouble shooting
 
Python my sql database connection
Python my sql   database connectionPython my sql   database connection
Python my sql database connection
Learnbay Datascience
 
Database presentation
Database presentationDatabase presentation
Database presentation
webhostingguy
 
Python my SQL - create table
Python my SQL - create tablePython my SQL - create table
Python my SQL - create table
Learnbay Datascience
 
Lecture6 display data by okello erick
Lecture6 display data by okello erickLecture6 display data by okello erick
Lecture6 display data by okello erick
okelloerick
 
Synapse india reviews on php and sql
Synapse india reviews on php and sqlSynapse india reviews on php and sql
Synapse india reviews on php and sql
saritasingh19866
 
Cake PHP 3 Presentaion
Cake PHP 3 PresentaionCake PHP 3 Presentaion
Cake PHP 3 Presentaion
glslarmenta
 
My_sql_with_php
My_sql_with_phpMy_sql_with_php
My_sql_with_php
Ishaq Shinwari
 
Request dispacther interface ppt
Request dispacther interface pptRequest dispacther interface ppt
Request dispacther interface ppt
Taha Malampatti
 
Semalt: 3 Steps To PHP Web Page Scraping Web
Semalt: 3 Steps To PHP Web Page Scraping WebSemalt: 3 Steps To PHP Web Page Scraping Web
Semalt: 3 Steps To PHP Web Page Scraping Web
ilovemyindia18
 
Php
PhpPhp
Php
ksujitha
 
Using php with my sql
Using php with my sqlUsing php with my sql
Using php with my sql
salissal
 
Php verses my sql
Php verses my sqlPhp verses my sql
Php verses my sql
SEO Training in Chandigarh
 
TYPO3 6.2 for extension developer
TYPO3 6.2 for extension developerTYPO3 6.2 for extension developer
TYPO3 6.2 for extension developer
Nicole Cordes
 
Mysql & Php
Mysql & PhpMysql & Php
Mysql & Php
Inbal Geffen
 
Php verses MySQL
Php verses MySQLPhp verses MySQL
Php verses MySQL
CBitss Technologies
 

Similar to Php mysql connectivity (20)

7. PHP and gaghhgashgfsgajhfkhshfasMySQL.pptx
7. PHP and gaghhgashgfsgajhfkhshfasMySQL.pptx7. PHP and gaghhgashgfsgajhfkhshfasMySQL.pptx
7. PHP and gaghhgashgfsgajhfkhshfasMySQL.pptx
berihun18
 
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docxModule 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
moirarandell
 
Connecting to my sql using PHP
Connecting to my sql using PHPConnecting to my sql using PHP
Connecting to my sql using PHP
Nisa Soomro
 
Collection of built in functions for manipulating MySQL databases.docx
Collection of built in functions for manipulating MySQL databases.docxCollection of built in functions for manipulating MySQL databases.docx
Collection of built in functions for manipulating MySQL databases.docx
KingKhaliilHayat
 
PHP and Mysql
PHP and MysqlPHP and Mysql
PHP and Mysql
Sankhadeep Roy
 
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
Dave Stokes
 
PHP with MySQL
PHP with MySQLPHP with MySQL
PHP with MySQL
wahidullah mudaser
 
chapter_Seven Database manipulation using php.pptx
chapter_Seven Database manipulation using php.pptxchapter_Seven Database manipulation using php.pptx
chapter_Seven Database manipulation using php.pptx
Getawu
 
Php 2
Php 2Php 2
Php 2
tnngo2
 
Node.js with MySQL.pdf
Node.js with MySQL.pdfNode.js with MySQL.pdf
Node.js with MySQL.pdf
SudhanshiBakre1
 
DIWE - Working with MySQL Databases
DIWE - Working with MySQL DatabasesDIWE - Working with MySQL Databases
DIWE - Working with MySQL Databases
Rasan Samarasinghe
 
All Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for NewbiesAll Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for Newbies
Dave Stokes
 
Chapter 3.1.pptx
Chapter 3.1.pptxChapter 3.1.pptx
Chapter 3.1.pptx
mebratu9
 
Mysql connection
Mysql connectionMysql connection
Mysql connection
beben benzy
 
Mysql DBI
Mysql DBIMysql DBI
Mysql DBI
Joe Christensen
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
ADARSH BHATT
 
harry presentation
harry presentationharry presentation
harry presentation
thembhani mapengo
 
Php mysq
Php mysqPhp mysq
Php mysq
prasanna pabba
 
Rits Brown Bag - PHP & PHPMyAdmin
Rits Brown Bag - PHP & PHPMyAdminRits Brown Bag - PHP & PHPMyAdmin
Rits Brown Bag - PHP & PHPMyAdmin
Right IT Services
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For Beginners
Priti Solanki
 
7. PHP and gaghhgashgfsgajhfkhshfasMySQL.pptx
7. PHP and gaghhgashgfsgajhfkhshfasMySQL.pptx7. PHP and gaghhgashgfsgajhfkhshfasMySQL.pptx
7. PHP and gaghhgashgfsgajhfkhshfasMySQL.pptx
berihun18
 
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docxModule 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
moirarandell
 
Connecting to my sql using PHP
Connecting to my sql using PHPConnecting to my sql using PHP
Connecting to my sql using PHP
Nisa Soomro
 
Collection of built in functions for manipulating MySQL databases.docx
Collection of built in functions for manipulating MySQL databases.docxCollection of built in functions for manipulating MySQL databases.docx
Collection of built in functions for manipulating MySQL databases.docx
KingKhaliilHayat
 
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
Dave Stokes
 
chapter_Seven Database manipulation using php.pptx
chapter_Seven Database manipulation using php.pptxchapter_Seven Database manipulation using php.pptx
chapter_Seven Database manipulation using php.pptx
Getawu
 
DIWE - Working with MySQL Databases
DIWE - Working with MySQL DatabasesDIWE - Working with MySQL Databases
DIWE - Working with MySQL Databases
Rasan Samarasinghe
 
All Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for NewbiesAll Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for Newbies
Dave Stokes
 
Chapter 3.1.pptx
Chapter 3.1.pptxChapter 3.1.pptx
Chapter 3.1.pptx
mebratu9
 
Mysql connection
Mysql connectionMysql connection
Mysql connection
beben benzy
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
ADARSH BHATT
 
Rits Brown Bag - PHP & PHPMyAdmin
Rits Brown Bag - PHP & PHPMyAdminRits Brown Bag - PHP & PHPMyAdmin
Rits Brown Bag - PHP & PHPMyAdmin
Right IT Services
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For Beginners
Priti Solanki
 
Ad

Recently uploaded (20)

MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 SlidesHow to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
National Information Standards Organization (NISO)
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
National Information Standards Organization (NISO)
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptxCapitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
Quiz Club of PSG College of Arts & Science
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 SlidesHow to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptxCapitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Ad

Php mysql connectivity

  • 1. PHP Mysql connectivity Use the mysql_connect( ) functiontoestablishedconnectiontothe MySQLserver.To accessthe database functionalitywe have tomake a connectiontodatabase usingPhp.mysql_connect() function isusedto establishthe connectiontomysql server. Four argumentsneedtobe passedtomysql_connect() function. Hostname : if you are working on local system , you can use localhost or you can also provide ip address or server name. username : if there is a existing user , you can provide username. default username is 'root'. password : by default password is blank or null. dbname : it is a optional field . it is basically a name of the database that need to be connected. mysql_connect(host, username, password, dbname); Parameter Description host(Server name) Either a host name(server name) or an IP address username The MySQL user name password The password to log in with dbname Optional. The database to be used when performing queries Note : There are more available parameters, but the ones listed above are the most important. In the following example we store the connection in a variable ($con) for later use in the script <?php // Create connection $con=mysql_connect("localhost","root","") or die(mysql_error()); ?> Here localhost is server name. root is MySQL default user name. default password is blank and database name is my_db. mysql_error( ) function provides mysql connectivity error message. MySQL Close Connection <?php // Create connection $con=mysql_connect("localhost","root","","my_db") or die(mysql_error()); //code to be executed...
  • 2. // Close connection mysql_close($con); ?> after work with the database is done we have to close the connection using mysql_close() function in which the connection to the database is passed. Mysqli PHP Connectivity How to connect PHP through mysqli. Create a registration form with 4 four fields name,email id, mobile number and address. Fill all the fields click on save data submit button to save your data inside "users" table using mysqli prepared statements insert. To display all the values from "users" table click on disp data button it will display the values using mysqli prepared statements select. Create Database and Table Database name:demo Table:user PHP Script(PHP mysqli connection ) <?php //mysqli connectivity $connect= new mysqli("localhost","root","","demo") or die("ERROR:could not connect to the database!!!!"); extract($_POST); if(isset($save)) { $query="insert into users values('','$n','$e','$m','$add')"; if($connect->query($query)) { echo 'congrates!! data saved'; }
  • 3. else { echo 'data not saved '.$connect->error; } } //display data if(isset($disp)) { $query="select * from users"; $result=$connect->query($query); echo "<table border=1>"; echo "<tr><th>Name</th><th>Email</th><th>Mobile< /th><th>Address</th></tr>"; while($row=$result->fetch_array()) { echo "<tr>"; echo "<td>".$row['name']."</td>"; echo "<td>".$row['email']."</td>"; echo "<td>".$row['mobile']."</td>"; echo "<td>".$row['address']."</td>"; echo "</tr>"; } echo "</table>"; } ?> HTML Form <style>
  • 4. input,textarea{width:200px} input[type=submit]{width:100px} </style> <form method="post"> <table width="218" border="0"> <tr> <td width="208"><input type="text" name="n" placeholder="Enter your name"/></td> </tr> <tr> <td><input type="text" name="e" placeholder="Enter your email"/></td> </tr> <tr> <td><input type="text" name="m" placeholder="Enter your mobile"/></td> </tr> <tr> <td><textarea name="add" placeholder="Enter your address"></textarea></td> </tr> <tr> <td> <input type="submit" name="save" value="Save Data"/> <input type="submit" name="disp" value="Display Data"/> </td> </tr> </table> </form>