SlideShare a Scribd company logo
<!DOCTYPE html>
<html lang="en">
<head>
<title>Store Data</title>
</head>
<body>
<center>
<h1>Storing Form data in Database</h1>
<form action="insert.php" method="post">
<p>
<label for="firstName">First Name:</label>
<input type="text" name="first_name" id="firstName">
</p>
<p>
<label for="lastName">Last Name:</label>
<input type="text" name="last_name" id="lastName">
</p>
<p>
<label for="Gender">Gender:</label>
<input type="text" name="gender" id="Gender">
</p>
<p>
<label for="Address">Address:</label>
<input type="text" name="address" id="Address">
</p>
<p>
<label for="emailAddress">Email Address:</label>
<input type="text" name="email" id="emailAddress">
</p>
<input type="submit" value="Submit">
</form>
</center>
</body>
</html>
****************************************************************
<?php
$first_name = $_REQUEST['first_name'];
$last_name = $_REQUEST['last_name'];
$gender = $_REQUEST['gender'];
$address = $_REQUEST['address'];
$email = $_REQUEST['email'];
$conn = mysqli_connect("localhost", "root", "", "staff");
if($conn === false)
{
die("ERROR: Could not connect." . mysqli_connect_error());
}
$sql = "INSERT INTO college VALUES('$first_name','$last_name','$gender','$address','$email')";
if(mysqli_query($conn, $sql))
{
echo "<h3>data stored in a database successfully.</h3>";
echo nl2br("n$first_namen $last_namen $gendern $addressn $email");
}
else
{
echo "ERROR:". mysqli_error($conn);
}
mysqli_close($conn);
?>
*****************************************************************************************
<?php
$conn = mysqli_connect("localhost", "root", "", "student_db");
if($conn === false)
{
die("ERROR: Could not connect." . mysqli_connect_error());
}
$sql = "SELECT first_name, last_name FROM student";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
echo "Name: " . $row["first_name"] . " " . $row["last_name"]. "<br>";
}
}
else
{
echo "0 results";
}
mysqli_close($conn);
?>
**************************************************************************************
<?php
$conn = mysqli_connect("localhost", "root", "", "student_db");
if($conn === false)
{
die("ERROR: Could not connect." . mysqli_connect_error());
}
$sql = "SELECT first_name, last_name FROM student WHERE last_name='Dutt'";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
echo "Name: " . $row["first_name"] . " " . $row["last_name"]. "<br>";
}
}
else
{
echo "0 results";
}
mysqli_close($conn);
?>
****************************************************************************************
<?php
$conn = mysqli_connect("localhost", "root", "", "student_db");
if($conn === false)
{
die("ERROR: Could not connect." . mysqli_connect_error());
}
$sql = "SELECT first_name, last_name FROM student ORDER BY first_name";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
echo "Name: " . $row["first_name"] . " " . $row["last_name"]. "<br>";
}
}
else
{
echo "0 results";
}
mysqli_close($conn);
?>
****************************************************************************************
The die() function is used to print the message. The exit() method exits the script or it may be used to print
alternate messages.
The mysqli_connect() function attempts to open a connection to the MySQL Server running on host which can
be either a host name or an IP address.
PHP $_REQUEST is a PHP super global variable which is used to collect data after submitting an HTML form.
The example below shows a form with an input field and a submit button. When a user submits the data by
clicking on "Submit", the form data is sent to the file specified in the action attribute of the <form> tag.
The mysqli_query() function accepts a string value representing a query as one of the parameters and,
executes/performs the given query on the database.

More Related Content

PPTX
PHP DATABASE MANAGEMENT.pptx
PPTX
Basics of Working with PHP and MySQL.pptx
DOC
Ex[1].3 php db connectivity
PDF
Php 2
PPTX
Connecting_to_Database(MySQL)_in_PHP.pptx
PPTX
This slide show will brief about database handling
DOCX
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
PDF
4.3 MySQL + PHP
PHP DATABASE MANAGEMENT.pptx
Basics of Working with PHP and MySQL.pptx
Ex[1].3 php db connectivity
Php 2
Connecting_to_Database(MySQL)_in_PHP.pptx
This slide show will brief about database handling
Module 6WEB SERVER AND SERVER SIDE SCRPTING, PART-2Chapte.docx
4.3 MySQL + PHP

Similar to The HyperText Markup Language or HTML is the standard markup language (20)

PPTX
7. PHP and gaghhgashgfsgajhfkhshfasMySQL.pptx
PDF
"PHP and MySQL CRUD Operations for Student Management System"
ODP
PPTX
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering College
PPTX
UNIT V (5).pptx
PDF
SULTHAN's - PHP MySQL programs
PPTX
3 php-connect-to-my sql
PDF
Stored Procedure
DOCX
Web Application PHP and MySQL Database
PPTX
Unit 4- Working with SQL.pptx
PDF
Php summary
PPTX
Learn PHP Lacture2
PPTX
CHAPTER six DataBase Driven Websites.pptx
PPTX
Amp and higher computing science
PPTX
Lecture 8 PHP and MYSQL part 2.ppType Classificationtx
PPT
P H P Part I I, By Kian
PPTX
3-Chapter-Edit.pptx debre tabour university
PPT
Download It
PPTX
Coding for php with mysql
PDF
Diving into php
7. PHP and gaghhgashgfsgajhfkhshfasMySQL.pptx
"PHP and MySQL CRUD Operations for Student Management System"
Database Connectivity MYSQL by Dr.C.R.Dhivyaa Kongu Engineering College
UNIT V (5).pptx
SULTHAN's - PHP MySQL programs
3 php-connect-to-my sql
Stored Procedure
Web Application PHP and MySQL Database
Unit 4- Working with SQL.pptx
Php summary
Learn PHP Lacture2
CHAPTER six DataBase Driven Websites.pptx
Amp and higher computing science
Lecture 8 PHP and MYSQL part 2.ppType Classificationtx
P H P Part I I, By Kian
3-Chapter-Edit.pptx debre tabour university
Download It
Coding for php with mysql
Diving into php

More from Lovely Professional University (20)

PPTX
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
PPTX
Effort Estimation: Meaning, Problems with Estimation, Basis, Estimation Techn...
PPTX
Project Approach: Intro. Technical Plan, Choice of Process Models: Waterfall,...
PPTX
Programme Management & Project Evaluation
PPTX
Step Wise Project Planning: Project Scope, Objectives, Infrastructure, Charac...
PPTX
Introduction to Software Project Management:
PPTX
PPTX
PPTX
Getting Input from User
PPTX
PPTX
Transaction Processing in DBMS.pptx
PPT
web_server_browser.ppt
PPTX
PPTX
Number System.pptx
PPT
Programming Language.ppt
PPTX
Information System.pptx
PPTX
Applications of Computer Science in Pharmacy-1.pptx
PPTX
Application of Computers in Pharmacy.pptx
PPTX
Deploying your app.pptx
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Effort Estimation: Meaning, Problems with Estimation, Basis, Estimation Techn...
Project Approach: Intro. Technical Plan, Choice of Process Models: Waterfall,...
Programme Management & Project Evaluation
Step Wise Project Planning: Project Scope, Objectives, Infrastructure, Charac...
Introduction to Software Project Management:
Getting Input from User
Transaction Processing in DBMS.pptx
web_server_browser.ppt
Number System.pptx
Programming Language.ppt
Information System.pptx
Applications of Computer Science in Pharmacy-1.pptx
Application of Computers in Pharmacy.pptx
Deploying your app.pptx

Recently uploaded (20)

PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Lesson notes of climatology university.
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Computing-Curriculum for Schools in Ghana
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
master seminar digital applications in india
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Pre independence Education in Inndia.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
102 student loan defaulters named and shamed – Is someone you know on the list?
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
O7-L3 Supply Chain Operations - ICLT Program
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
TR - Agricultural Crops Production NC III.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Lesson notes of climatology university.
Abdominal Access Techniques with Prof. Dr. R K Mishra
Renaissance Architecture: A Journey from Faith to Humanism
Computing-Curriculum for Schools in Ghana
FourierSeries-QuestionsWithAnswers(Part-A).pdf
master seminar digital applications in india
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPH.pptx obstetrics and gynecology in nursing
Pre independence Education in Inndia.pdf
Supply Chain Operations Speaking Notes -ICLT Program
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...

The HyperText Markup Language or HTML is the standard markup language

  • 1. <!DOCTYPE html> <html lang="en"> <head> <title>Store Data</title> </head> <body> <center> <h1>Storing Form data in Database</h1> <form action="insert.php" method="post"> <p> <label for="firstName">First Name:</label> <input type="text" name="first_name" id="firstName"> </p> <p> <label for="lastName">Last Name:</label> <input type="text" name="last_name" id="lastName"> </p> <p> <label for="Gender">Gender:</label> <input type="text" name="gender" id="Gender"> </p> <p> <label for="Address">Address:</label> <input type="text" name="address" id="Address"> </p> <p> <label for="emailAddress">Email Address:</label> <input type="text" name="email" id="emailAddress"> </p> <input type="submit" value="Submit"> </form> </center> </body> </html> **************************************************************** <?php $first_name = $_REQUEST['first_name']; $last_name = $_REQUEST['last_name']; $gender = $_REQUEST['gender']; $address = $_REQUEST['address']; $email = $_REQUEST['email']; $conn = mysqli_connect("localhost", "root", "", "staff"); if($conn === false) { die("ERROR: Could not connect." . mysqli_connect_error()); } $sql = "INSERT INTO college VALUES('$first_name','$last_name','$gender','$address','$email')";
  • 2. if(mysqli_query($conn, $sql)) { echo "<h3>data stored in a database successfully.</h3>"; echo nl2br("n$first_namen $last_namen $gendern $addressn $email"); } else { echo "ERROR:". mysqli_error($conn); } mysqli_close($conn); ?> ***************************************************************************************** <?php $conn = mysqli_connect("localhost", "root", "", "student_db"); if($conn === false) { die("ERROR: Could not connect." . mysqli_connect_error()); } $sql = "SELECT first_name, last_name FROM student"; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo "Name: " . $row["first_name"] . " " . $row["last_name"]. "<br>"; } } else { echo "0 results"; } mysqli_close($conn); ?> ************************************************************************************** <?php $conn = mysqli_connect("localhost", "root", "", "student_db"); if($conn === false) { die("ERROR: Could not connect." . mysqli_connect_error()); } $sql = "SELECT first_name, last_name FROM student WHERE last_name='Dutt'"; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc())
  • 3. { echo "Name: " . $row["first_name"] . " " . $row["last_name"]. "<br>"; } } else { echo "0 results"; } mysqli_close($conn); ?> **************************************************************************************** <?php $conn = mysqli_connect("localhost", "root", "", "student_db"); if($conn === false) { die("ERROR: Could not connect." . mysqli_connect_error()); } $sql = "SELECT first_name, last_name FROM student ORDER BY first_name"; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo "Name: " . $row["first_name"] . " " . $row["last_name"]. "<br>"; } } else { echo "0 results"; } mysqli_close($conn); ?> **************************************************************************************** The die() function is used to print the message. The exit() method exits the script or it may be used to print alternate messages. The mysqli_connect() function attempts to open a connection to the MySQL Server running on host which can be either a host name or an IP address. PHP $_REQUEST is a PHP super global variable which is used to collect data after submitting an HTML form. The example below shows a form with an input field and a submit button. When a user submits the data by clicking on "Submit", the form data is sent to the file specified in the action attribute of the <form> tag. The mysqli_query() function accepts a string value representing a query as one of the parameters and, executes/performs the given query on the database.