Mysql Insert Update Delete Operation using PHP
Step 1: First of all start your wamp/xampp server and open phpmyadmin tool For this open http://localhost/phpmyadmin in your browser.
Step 2: Second click on SQL tab and create a database named testdb and insert two values in it with following script.
Step 2: Second click on SQL tab and create a database named testdb and insert two values in it with following script.
create database testdb;
use testdb;
create table members(id int primary key auto_increment,
name varchar(100),email varchar(200),password varchar(100));
insert into members(name,email,password)
values('raggu','raggu@gmail.com','1234'),
('hardik','hardik@gmail.com','1234');
index.php<!DOCTYPE html> <html lang="en"> <head> <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> <title>PHP Users List</title> <!-- Bootstrap --> <!-- Latest compiled and minified CSS --> <link crossorigin="anonymous" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" rel="stylesheet"></link> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script> <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> <![endif]--> </head> <body> <div class="container"> <div class="row"> <nav class="nav"> <ul class="nav navbar-nav"> <li><a href="https://www.blogger.com/reg_form.php">Register</a></li> </ul> </nav></div> <h1> Users List</h1> <div class="row"> <table class="table table-bordered table-hover table-striped"> <tr><th>ID</th><th>Name</th> <th>Email</th><th>Password</th> <th>Delete</th><th>Edit</th></tr> <tr> <td></td> <td></td> <td></td> <td></td> <td><a br="" href="https://www.blogger.com/user_delete.php?id=%3C?php%20echo%20$row[0];?%3E"> class="btn btn-danger btn-xs">Delete</a></td> <td><a br="" href="https://www.blogger.com/user_edit_form.php?id=%3C?php%20echo%20$row[0];?%3E"> class="btn btn-warning btn-xs">Edit</a></td> </tr> </table> </div> </div> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <!-- Include all compiled plugins (below), or include individual files as needed --> <script src="js/bootstrap.min.js"></script> </body> </html>output of index.php
reg_form.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<title>Registration Form</title>
</head>
<body>
<div class="container">
<!-- Top Row Start-->
<div class="row">
<nav class="nav">
<ul class="nav navbar-nav">
<li><a href="reg_form.php">Register</a></li>
</ul>
</div>
<!-- Top Row finish-->
<!-- Main Row area-->
<div class="row">
<div class="col-sm-2"></div>
<div class="col-sm-8">
<h1>Registation Form</h1>
<form action="show.php" method="get">
<input type="text" name="name" id="" class="" placeholder="Name"/>
<br/>
<input type="text" name="email" id="" class="" placeholder="yourmail@domain.com"/>
<br/>
<input type="password" name="password" id="" class="" placeholder="Password"/>
<br/>
<br/>
<input type="submit" value="Register" name="" id="" class="btn btn-primary" />
<br/>
</form>
</div>
<div class="col-sm-2"></div>
</div>
<!-- Main Row area finish-->
</div>
</body>
</html>
user_delete.php<?php
$id=$_GET['id'];
$conn=mysqli_connect('localhost','root','','testdb');
$sql="delete from members where id='$id'";
$success=mysqli_query($conn,$sql);
if($success)echo"Member deleted successfully";
?>
user_edit_form.php<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<title>Registration Form</title>
</head>
<body>
<div class="container">
<!-- Top Row Start-->
<div class="row">Top Menu </div>
<!-- Top Row finish-->
<!-- Main Row area-->
<div class="row">
<div class="col-sm-2"></div>
<div class="col-sm-8">
<h1>Edit Profile Form</h1>
<?php
$id=$_GET['id'];
$conn=mysqli_connect('localhost','root','','jashan');
$sql1="select * from members where id=$id";
$rs=mysqli_query($conn,$sql1);
while($row=mysqli_fetch_array($rs)){
?>
<form action="user_update.php" method="get">
<input type="text" value="<?php echo $row[0];?>"name="id" id="" class="" placeholder="Name"/>
<br/>
<input type="text" value="<?php echo $row[1];?>"name="name" id="" class="" placeholder="Name"/>
<br/>
<input type="text" value="<?php echo $row[2];?>" name="email" id="" class="" placeholder="yourmail@domain.com"/>
<br/>
<input type="password" value="<?php echo $row[3];?>" name="password" id="" class="" placeholder="Password"/>
<?php } ?>
<br/>
<br/>
<input type="submit" value="Update" name="" id="" class="btn btn-primary" />
<br/>
</form>
</div>
<div class="col-sm-2"></div>
</div>
<!-- Main Row area finish-->
</div>
</body>
</html>
user_update.php<?php
$id=$_GET['id'];
$name=$_GET['name'];
$email=$_GET['email'];
$password=$_GET['password'];
$conn=mysqli_connect('localhost','root','','testdb');
$sql="update members set name='$name',
email='$email',password='$password' where id='$id'";
$success=mysqli_query($conn,$sql);
if($success)echo"Member Updated successfully";
?>

No comments:
Post a Comment