INSERT , RETRIEVE , DELETE & UPDATE BUTTON IN PHP MYSQL WITH DATABASE
This artical is going to very much for you if you are a beggineer in web developing. In this artical I you will be read about how to insert & retrieve image from the database and how to make delete and update system. The source code are under below the some lines. You can copy and pest it in your text editor. The codes are very simple , not difficult to read and understand it if you are begneers.
In this artical I will give you full tutorial through a project.
About the project
In this project, you can insert data in database and also retrieve it from the database. You will be also find delete and update button also. By click delete button the data id will be delete and if you click update button then a new tab will be open in the new tab you will be find text updatin areas you can update all text by the update button clicking.
So please read the whoole project it will be very much helpfull for you.
this project is supported all browser like googlechrome, firefox, oprea mini yaahu etc.
follow these steps
open you xampp folder and localhost/phpmyadmin
make a database named by demo. In this database make a row named by demosystem.
1. Create an database
create database named as demo and create a row named by demosystem
make these five colummns 'id' 'name' 'city' 'mobile' 'email'
'id' value should be int(11) & autoincreament, name value should be varch(255), 'city' value varchar(255), 'mobile' value varchar(255), email varchar(255).
2. Create an index.php file
index.php file path should be xampp/htdocs/project/index.php
type the html5 code with bootsrap in your index.php file.
<!DOCTYPE html>
<html lang="en">
<head>
<title>tittle</title>
<link rel="icon" type="image/jpg" href="image/team-6.jpg" />
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<!-- Optional theme -->
</head>
<body>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
3. Make database connection
to make database connection type these database connection code.
<?php
$db_host = "localhost";
$db_user = "root";
$db_password = "";
$db_name = "demo";
// Create Connection
$conn = new mysqli($db_host, $db_user, $db_password, $db_name);
// Check Connection
if($conn->connect_error) {
die("connection failed");
}
?>
4. php code
write this code in the body section of your index.php file. This is in html design. Data submitting form.
<div class="col-sm-6 mt-5 mx-3 jumbotron">
<h3 class="text-center">Add New Technician</h3>
<form action="" method="POST">
<div class="form-group">
<label for="empName">Name</label>
<input type="text" class="form-control" id="empName" name="empName">
</div>
<div class="form-group">
<label for="empCity">City</label>
<input type="text" class="form-control" id="empCity" name="empCity">
</div>
<div class="form-group">
<label for="empMobile">Mobile</label>
<input type="text" class="form-control" id="empMobile" name="empMobile" onkeypress="isInputNumber(event)">
</div>
<div class="form-group">
<label for="empEmail">Email</label>
<input type="email" class="form-control" id="empEmail" name="empEmail">
</div>
<div class="text-center">
<button type="submit" class="btn btn-danger" id="empsubmit" onclick="return mess();" name="empsubmit">Submit</button>
<a href="technician.php" class="btn btn-secondary">Close</a>
</div>
<?php if(isset($msg)) {echo $msg; } ?>
</form>
<a class="btn btn-danger box" href="form.php"><i class="fas fa-plus fa-2x"></i></a>
</div>
<!-- Only Number for input fields -->
<script type="text/JavaScript">
function mess()
{
alert ("your record is succefully");
return true;
}
now we have to create a php file by this file we make a code . By this code we will be able to insert data in the database. We will complete this in php and mysql.
By these code if the user click on the submit button the dcetail in the form will be store in the database.
<?php
if(isset($_REQUEST['empsubmit'])){
// Checking for Empty Fields
if(($_REQUEST['empName'] == "") || ($_REQUEST['empCity'] == "") || ($_REQUEST['empMobile'] == "") || ($_REQUEST['empEmail'] == "")){
// msg displayed if required field missing
$msg = '<div class="alert alert-warning col-sm-6 ml-5 mt-2" role="alert"> Fill All Fileds </div>';
} else {
// Assigning User Values to Variable
$eName = $_REQUEST['empName'];
$eCity = $_REQUEST['empCity'];
$eMobile = $_REQUEST['empMobile'];
$eEmail = $_REQUEST['empEmail'];
$sql = "INSERT INTO demosystem (empName, empCity, empMobile, empEmail) VALUES ('$eName', '$eCity','$eMobile', '$eEmail')";
if($conn->query($sql) == TRUE){
header("Location:index.php");
exit;
}
// below msg display on form submit success
else {
// below msg display on form submit failed
$msg = '<div class="alert alert-danger col-sm-6 ml-5 mt-2" role="alert"> Unable to Add </div>';
}
}
}
?>
after copy these code in your php file you will be able to insert data in row. Please try this code in your php file. If you have any error you can surely message me I will be make proper solution of your problem.
Our next step is to retrieve data form the database
3. Retrieve data from the database
Our next step is this to retrieve or fetch data from the database. This step is very simple. To retrieve data in your fiel , first create a file named by fetchfile.php . This file path should be xampp/htdocs/project/fetchfile.php In the same path of index.php. In this file we will retrieve data from the database demo
to retieve data first pest the code below the lines.
<?php
$db_host = "localhost";
$db_user = "root";
$db_password = "";
$db_name = "demo";
// Create Connection
$conn = new mysqli($db_host, $db_user, $db_password, $db_name);
// Check Connection
if($conn->connect_error) {
die("connection failed");
}
if(isset($_REQUEST['empsubmit'])){
// Checking for Empty Fields
if(($_REQUEST['empName'] == "") || ($_REQUEST['empCity'] == "") || ($_REQUEST['empMobile'] == "") || ($_REQUEST['empEmail'] == "")){
// msg displayed if required field missing
$msg = '<div class="alert alert-warning col-sm-6 ml-5 mt-2" role="alert"> Fill All Fileds </div>';
} else {
// Assigning User Values to Variable
$eName = $_REQUEST['empName'];
$eCity = $_REQUEST['empCity'];
$eMobile = $_REQUEST['empMobile'];
$eEmail = $_REQUEST['empEmail'];
$sql = "INSERT INTO demosystem (empName, empCity, empMobile, empEmail) VALUES ('$eName', '$eCity','$eMobile', '$eEmail')";
if($conn->query($sql) == TRUE){
header("Location:index.php");
exit;
}
// below msg display on form submit success
else {
// below msg display on form submit failed
$msg = '<div class="alert alert-danger col-sm-6 ml-5 mt-2" role="alert"> Unable to Add </div>';
}
}
}
?>
<div class="col-sm-6 mt-5 mx-3 jumbotron">
<h3 class="text-center">Add New Technician</h3>
<form action="" method="POST">
<div class="form-group">
<label for="empName">Name</label>
<input type="text" class="form-control" id="empName" name="empName">
</div>
<div class="form-group">
<label for="empCity">City</label>
<input type="text" class="form-control" id="empCity" name="empCity">
</div>
<div class="form-group">
<label for="empMobile">Mobile</label>
<input type="text" class="form-control" id="empMobile" name="empMobile" onkeypress="isInputNumber(event)">
</div>
<div class="form-group">
<label for="empEmail">Email</label>
<input type="email" class="form-control" id="empEmail" name="empEmail">
</div>
<div class="text-center">
<button type="submit" class="btn btn-danger" id="empsubmit" onclick="return mess();" name="empsubmit">Submit</button>
<a href="technician.php" class="btn btn-secondary">Close</a>
</div>
<?php if(isset($msg)) {echo $msg; } ?>
</form>
<a class="btn btn-danger box" href="form.php"><i class="fas fa-plus fa-2x"></i></a>
</div>
<!-- Only Number for input fields -->
<script type="text/JavaScript">
function mess()
{
alert ("your record is succefully");
return true;
}
</script>
<script>
function isInputNumber(evt) {
var ch = String.fromCharCode(evt.which);
if (!(/[0-9]/.test(ch))) {
evt.preventDefault();
}
}
</script>
<?php
include('includes/footer.php');
?>
This artical is going to very much for you if you are a beggineer in web developing. In this artical I you will be read about how to insert & retrieve image from the database and how to make delete and update system. The source code are under below the some lines. You can copy and pest it in your text editor. The codes are very simple , not difficult to read and understand it if you are begneers.
In this artical I will give you full tutorial through a project.
About the project
In this project, you can insert data in database and also retrieve it from the database. You will be also find delete and update button also. By click delete button the data id will be delete and if you click update button then a new tab will be open in the new tab you will be find text updatin areas you can update all text by the update button clicking.
So please read the whoole project it will be very much helpfull for you.
this project is supported all browser like googlechrome, firefox, oprea mini yaahu etc.
follow these steps
open you xampp folder and localhost/phpmyadmin
make a database named by demo. In this database make a row named by demosystem.
1. Create an database
create database named as demo and create a row named by demosystem
make these five colummns 'id' 'name' 'city' 'mobile' 'email'
'id' value should be int(11) & autoincreament, name value should be varch(255), 'city' value varchar(255), 'mobile' value varchar(255), email varchar(255).
2. Create an index.php file
index.php file path should be xampp/htdocs/project/index.php
type the html5 code with bootsrap in your index.php file.
<!DOCTYPE html>
<html lang="en">
<head>
<title>tittle</title>
<link rel="icon" type="image/jpg" href="image/team-6.jpg" />
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<!-- Optional theme -->
</head>
<body>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
3. Make database connection
to make database connection type these database connection code.
<?php
$db_host = "localhost";
$db_user = "root";
$db_password = "";
$db_name = "demo";
// Create Connection
$conn = new mysqli($db_host, $db_user, $db_password, $db_name);
// Check Connection
if($conn->connect_error) {
die("connection failed");
}
?>
4. php code
write this code in the body section of your index.php file. This is in html design. Data submitting form.
<div class="col-sm-6 mt-5 mx-3 jumbotron">
<h3 class="text-center">Add New Technician</h3>
<form action="" method="POST">
<div class="form-group">
<label for="empName">Name</label>
<input type="text" class="form-control" id="empName" name="empName">
</div>
<div class="form-group">
<label for="empCity">City</label>
<input type="text" class="form-control" id="empCity" name="empCity">
</div>
<div class="form-group">
<label for="empMobile">Mobile</label>
<input type="text" class="form-control" id="empMobile" name="empMobile" onkeypress="isInputNumber(event)">
</div>
<div class="form-group">
<label for="empEmail">Email</label>
<input type="email" class="form-control" id="empEmail" name="empEmail">
</div>
<div class="text-center">
<button type="submit" class="btn btn-danger" id="empsubmit" onclick="return mess();" name="empsubmit">Submit</button>
<a href="technician.php" class="btn btn-secondary">Close</a>
</div>
<?php if(isset($msg)) {echo $msg; } ?>
</form>
<a class="btn btn-danger box" href="form.php"><i class="fas fa-plus fa-2x"></i></a>
</div>
<!-- Only Number for input fields -->
<script type="text/JavaScript">
function mess()
{
alert ("your record is succefully");
return true;
}
now we have to create a php file by this file we make a code . By this code we will be able to insert data in the database. We will complete this in php and mysql.
By these code if the user click on the submit button the dcetail in the form will be store in the database.
<?php
if(isset($_REQUEST['empsubmit'])){
// Checking for Empty Fields
if(($_REQUEST['empName'] == "") || ($_REQUEST['empCity'] == "") || ($_REQUEST['empMobile'] == "") || ($_REQUEST['empEmail'] == "")){
// msg displayed if required field missing
$msg = '<div class="alert alert-warning col-sm-6 ml-5 mt-2" role="alert"> Fill All Fileds </div>';
} else {
// Assigning User Values to Variable
$eName = $_REQUEST['empName'];
$eCity = $_REQUEST['empCity'];
$eMobile = $_REQUEST['empMobile'];
$eEmail = $_REQUEST['empEmail'];
$sql = "INSERT INTO demosystem (empName, empCity, empMobile, empEmail) VALUES ('$eName', '$eCity','$eMobile', '$eEmail')";
if($conn->query($sql) == TRUE){
header("Location:index.php");
exit;
}
// below msg display on form submit success
else {
// below msg display on form submit failed
$msg = '<div class="alert alert-danger col-sm-6 ml-5 mt-2" role="alert"> Unable to Add </div>';
}
}
}
?>
after copy these code in your php file you will be able to insert data in row. Please try this code in your php file. If you have any error you can surely message me I will be make proper solution of your problem.
Our next step is to retrieve data form the database
3. Retrieve data from the database
Our next step is this to retrieve or fetch data from the database. This step is very simple. To retrieve data in your fiel , first create a file named by fetchfile.php . This file path should be xampp/htdocs/project/fetchfile.php In the same path of index.php. In this file we will retrieve data from the database demo
to retieve data first pest the code below the lines.
<?php
$db_host = "localhost";
$db_user = "root";
$db_password = "";
$db_name = "demo";
// Create Connection
$conn = new mysqli($db_host, $db_user, $db_password, $db_name);
// Check Connection
if($conn->connect_error) {
die("connection failed");
}
if(isset($_REQUEST['empsubmit'])){
// Checking for Empty Fields
if(($_REQUEST['empName'] == "") || ($_REQUEST['empCity'] == "") || ($_REQUEST['empMobile'] == "") || ($_REQUEST['empEmail'] == "")){
// msg displayed if required field missing
$msg = '<div class="alert alert-warning col-sm-6 ml-5 mt-2" role="alert"> Fill All Fileds </div>';
} else {
// Assigning User Values to Variable
$eName = $_REQUEST['empName'];
$eCity = $_REQUEST['empCity'];
$eMobile = $_REQUEST['empMobile'];
$eEmail = $_REQUEST['empEmail'];
$sql = "INSERT INTO demosystem (empName, empCity, empMobile, empEmail) VALUES ('$eName', '$eCity','$eMobile', '$eEmail')";
if($conn->query($sql) == TRUE){
header("Location:index.php");
exit;
}
// below msg display on form submit success
else {
// below msg display on form submit failed
$msg = '<div class="alert alert-danger col-sm-6 ml-5 mt-2" role="alert"> Unable to Add </div>';
}
}
}
?>
<div class="col-sm-6 mt-5 mx-3 jumbotron">
<h3 class="text-center">Add New Technician</h3>
<form action="" method="POST">
<div class="form-group">
<label for="empName">Name</label>
<input type="text" class="form-control" id="empName" name="empName">
</div>
<div class="form-group">
<label for="empCity">City</label>
<input type="text" class="form-control" id="empCity" name="empCity">
</div>
<div class="form-group">
<label for="empMobile">Mobile</label>
<input type="text" class="form-control" id="empMobile" name="empMobile" onkeypress="isInputNumber(event)">
</div>
<div class="form-group">
<label for="empEmail">Email</label>
<input type="email" class="form-control" id="empEmail" name="empEmail">
</div>
<div class="text-center">
<button type="submit" class="btn btn-danger" id="empsubmit" onclick="return mess();" name="empsubmit">Submit</button>
<a href="technician.php" class="btn btn-secondary">Close</a>
</div>
<?php if(isset($msg)) {echo $msg; } ?>
</form>
<a class="btn btn-danger box" href="form.php"><i class="fas fa-plus fa-2x"></i></a>
</div>
<!-- Only Number for input fields -->
<script type="text/JavaScript">
function mess()
{
alert ("your record is succefully");
return true;
}
</script>
<script>
function isInputNumber(evt) {
var ch = String.fromCharCode(evt.which);
if (!(/[0-9]/.test(ch))) {
evt.preventDefault();
}
}
</script>
<?php
include('includes/footer.php');
?>
No comments:
Post a Comment
thanks for your comments