CRUD Operation in PHP MySQL with Code. Select Insert Update Delete in PHP MySQLi
First of all, I already made a detailed video on it if you haven't watch it.
Below is the video link.
What is CRUD Operation and it is the most important part for any programmers?
CRUD full form is CREATE, READ, UPDATE & DELETE. So it is clear we have to first CREATE a database and a form. Which we can READ here we refer to both programmers and users those who interact with our sites. There must an option where the user can UPDATE the form details and also DELETE it.
All the features if available then that is called a perfect CRUD operation and this is what mostly backend developer deal with.
First, we will see the Database Part. So here is the con.php file.
You have to make sure that your username and password is set or not. I mean I never set any username and password for my localhost. So that is the reason why you can see in mysqli_connect, I have written localhost and root, here the root is the username that is by default if you never set by your own. And there is no need to write password because it's empty by default but if you have one add it after the root.
Also, make sure that your database name must me crudyoutube because below you can see I have written crudyoutube. If you want to write other names simply change the database name on PHPMyAdmin and add that here.
<?php
$con = mysqli_connect('localhost','root');
mysqli_select_db($con,'crudyoutube');
?>
$con = mysqli_connect('localhost','root');
mysqli_select_db($con,'crudyoutube');
?>
Fine, Here is the Insert.php file. Where we are actually inserting the Name and Password.
As you can see all the CDN link are already here in the code below. So no need to take from anywhere else just copy and paste it.
<?php
include 'conn.php';
if(isset($_POST['done'])){
$username = $_POST['username'];
$password = $_POST['password'];
$q = " INSERT INTO `crudtable`(`username`, `password`) VALUES ( '$username', '$password' )";
$query = mysqli_query($con,$q);
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="col-lg-6 m-auto">
<form method="post">
<br><br><div class="card">
<div class="card-header bg-dark">
<h1 class="text-white text-center"> Insert Operation </h1>
</div><br>
<label> Username: </label>
<input type="text" name="username" class="form-control"> <br>
<label> Password: </label>
<input type="text" name="password" class="form-control"> <br>
<button class="btn btn-success" type="submit" name="done"> Submit </button><br>
</div>
</form>
</div>
</body>
</html>
include 'conn.php';
if(isset($_POST['done'])){
$username = $_POST['username'];
$password = $_POST['password'];
$q = " INSERT INTO `crudtable`(`username`, `password`) VALUES ( '$username', '$password' )";
$query = mysqli_query($con,$q);
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="col-lg-6 m-auto">
<form method="post">
<br><br><div class="card">
<div class="card-header bg-dark">
<h1 class="text-white text-center"> Insert Operation </h1>
</div><br>
<label> Username: </label>
<input type="text" name="username" class="form-control"> <br>
<label> Password: </label>
<input type="text" name="password" class="form-control"> <br>
<button class="btn btn-success" type="submit" name="done"> Submit </button><br>
</div>
</form>
</div>
</body>
</html>
Display.php file
This is the main display page where we will show all the interface that we want too. We want to have a nice table where the user can see their Names, Password, Delete Button and Update Button.
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="https://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
</head>
<body>
<div class="container">
<div class="col-lg-12">
<br><br>
<h1 class="text-warning text-center" > Display Table Data </h1>
<br>
<table id="tabledata" class=" table table-striped table-hover table-bordered">
<tr class="bg-dark text-white text-center">
<th> Id </th>
<th> Username </th>
<th> Password </th>
<th> Delete </th>
<th> Update </th>
</tr >
<?php
include 'conn.php';
$q = "select * from crudtable ";
$query = mysqli_query($con,$q);
while($res = mysqli_fetch_array($query)){
?>
<tr class="text-center">
<td> <?php echo $res['id']; ?> </td>
<td> <?php echo $res['username']; ?> </td>
<td> <?php echo $res['password']; ?> </td>
<td> <button class="btn-danger btn"> <a href="delete.php?id=<?php echo $res['id']; ?>" class="text-white"> Delete </a> </button> </td>
<td> <button class="btn-primary btn"> <a href="update.php?id=<?php echo $res['id']; ?>" class="text-white"> Update </a> </button> </td>
</tr>
<?php
}
?>
</table>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#tabledata').DataTable();
})
</script>
</body>
</html>
Delete.php file
Here If anytime user wants to delete any field by simply click on the delete button, the user can do it. Is it that simple?
<?php
include 'conn.php';
$id = $_GET['id'];
$q = " DELETE FROM `crudtable` WHERE id = $id ";
mysqli_query($con, $q);
header('location:display.php');
?>
include 'conn.php';
$id = $_GET['id'];
$q = " DELETE FROM `crudtable` WHERE id = $id ";
mysqli_query($con, $q);
header('location:display.php');
?>
Update.php file
Here If anytime user wants to update any field by simply click on the update button, the user can do it. Is it that simple? You have to simply copy it and paste. This is the last part and I hope my video and source code helps you.
<?php
include 'conn.php';
if(isset($_POST['done'])){
$id = $_GET['id'];
$username = $_POST['username'];
$password = $_POST['password'];
$q = " update crudtable set id=$id, username='$username', password='$password' where id=$id ";
$query = mysqli_query($con,$q);
header('location:display.php');
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="col-lg-6 m-auto">
<form method="post">
<br><br><div class="card">
<div class="card-header bg-dark">
<h1 class="text-white text-center"> Update Operation </h1>
</div><br>
<label> Username: </label>
<input type="text" name="username" class="form-control"> <br>
<label> Password: </label>
<input type="text" name="password" class="form-control"> <br>
<button class="btn btn-success" type="submit" name="done"> Submit </button><br>
</div>
</form>
</div>
</body>
</html>
include 'conn.php';
if(isset($_POST['done'])){
$id = $_GET['id'];
$username = $_POST['username'];
$password = $_POST['password'];
$q = " update crudtable set id=$id, username='$username', password='$password' where id=$id ";
$query = mysqli_query($con,$q);
header('location:display.php');
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="col-lg-6 m-auto">
<form method="post">
<br><br><div class="card">
<div class="card-header bg-dark">
<h1 class="text-white text-center"> Update Operation </h1>
</div><br>
<label> Username: </label>
<input type="text" name="username" class="form-control"> <br>
<label> Password: </label>
<input type="text" name="password" class="form-control"> <br>
<button class="btn btn-success" type="submit" name="done"> Submit </button><br>
</div>
</form>
</div>
</body>
</html>
hi how can you show the one you edit?
ReplyDeletevalue=" ">
value=" ">
but it doesn'y work. please help.
can you give Source Code for me brother
ReplyDeleteDownload from here: https://phpcoder.tech/download/download-source-code-simple-php-mysql-crud-operation/
Deletevery nice
ReplyDeletei am practicing but i have got an error .I can't solve it .can u help me
ReplyDeletecan you help me, the coding is okay but it doesnt do what it suppose to do
ReplyDeleteI need this in ZIP or rar
ReplyDeletewothless
ReplyDelete
ReplyDeleteWarning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in E:\xampp\htdocs\crud\display.php on line 42............
i m getting this error sir please help...please
source code file download please
ReplyDeleteVery useful for me..
ReplyDeleteall is well but when i click on update button and show the page of update then when i edit the data and click on submit button then it go to the insert page and cannot update the data
ReplyDeletedisplay code hase some error 47 line error
ReplyDeletewhile i am inserting data it doesnot insert data in sql table even i put echo iin the
ReplyDeletephp code it will not reflect please help
Very nice Thapa Ji...its really helpfull for me..
ReplyDeletetnx ma bro
ReplyDeletecan you please add the search query with CRUD and add more details what your writing more detail for learning
ReplyDeleteGreat article with excellent idea! Thank you for such a valuable article. I really appreciate for this great information.
ReplyDeletephp software developers
Important Thank you dear!
ReplyDeleteThis is a really too good post. This article gives truly quality and helpful information. I’m definitely going to look into it. Really very useful topic info is provided here. Thank you so much buddy and Keep up the good work.badbunnymerch
ReplyDeleteThank you brother. I want to make such a database but I couldn't find any tutorials that you give us.
ReplyDeleteIt's high in antioxidants and cleans pollutants out of your hair, so you won't be caught in a hair follicle drug test. You should use it in conjunction with Zydot Ultra Clean, which is recommended as a companion product on the company's website. Of these, the hair follicle drug test is the toughest to crack as this hair testing can detect the presence of THC metabolites in the body for the longest period — at least three months after last consumption. That’s because an average person’s hair grows about half an inch per month. Testclear’s Drug Test Kit is one of the most reliable home marijuana detox kits by a long shot. The test uses your urine to identify remnants of THC in your system. Visit: https://www.urineworld.com/
ReplyDeleteIn this contemporary world, it has become responsible to get to each and everything with present day advances; subsequently, gaming peripherals are the best gaming gadgets which solace the gamers who love to play the best games with simple and open gadget to play their abilities. 먹튀사이트
ReplyDelete토토사이트
I have read your excellent post. This is a great job. I have enjoyed reading your post first time. I want to say thanks for this post. Thank you. 토토커뮤니티순위
ReplyDeletePlease continue to post good comments. l come every day. Please. 메이저안전사이트
ReplyDeletePlease continue to post good comments. l come every day. Please. 토토추천사이트
ReplyDeleteThey were active listeners and viewed meetings article. 안전토토사이트 This post is really the best on this valuable topic
ReplyDeleteI like your blog. i ma happy to read your blog its very informative and your blog is really good and impressive 메이저사이트
ReplyDeleteI read this article. I think You put a great deal of exertion to make this article. I like your
ReplyDeletefuct
it's really nice and meanful. it's really cool blog. Linking is very useful thing.you have really helped lots of people who visit blog and provide them usefull information. juicewrldmerch999.store
ReplyDeleteYour texts on this subject are correct, see how I wrote this site is really very good. playboyhoodie
ReplyDeleteI am very glad to read this article. I appreciate your work and inspiration. I also recommended my friends at
ReplyDeletemensslippersmaker to explore this domain.
I feel extremely cheerful to have seen your post. I found the most beautiful and fascinating one.mens marvel dressing gown I am really extremely glad to visit your post.
ReplyDeleteI enjoyed reading your blog and it contains a lot of information. sheepskinslippershub is also related to fashion in which you will find beautiful and charming sleepers made of sheepskin.
ReplyDeleteTechnomerch blade
ReplyDeleteTechnomerch blade
Technomerch blade
Technomerch blade
Technomerch blade
Technomerch blade
Technomerch blade
Technomerch blade
ReplyDeleteI read this article. I think You put a great deal of exertion to make this article.shoptechnoblade.com I like your
.
Nice and interesting post Shop Now, I appreciate your hard work, keep uploading more, Thank you for sharing valuable information.
ReplyDeleteI love this! such a great message. it’s a very nice blog.
ReplyDeleteทางเข้าเล่น igoal
I read this article. I think you put a great deal of exertion to make this article. ChelseaBootsMaker
ReplyDeleteGreat website you have got here.shop Here
ReplyDeleteKeep up the good work and thanks for sharing your blog site it really help a lot.
This will work in live server
ReplyDeleteThank you for this coding. Phone Price
ReplyDeletequackitymerch.net
ReplyDeletequackitymerch.net
quackitymerch.net
quackitymerch.net
quackitymerch.net
quackitymerch.net
quackitymerch.net
quackitymerch.net
quackitymerch.net
This amazing hearings completely acceptable. Most of simple facts are ready through great number connected with practical knowledge realistic expertise. https://chukkabootsmaker.com/ Now i am confident the item all over again completely.
ReplyDelete
DeleteIts blog give information from another people very well I am impress its information an information is very nice.
Click Here
Hiya, I’m really glad I have found this information. Nowadays bloggers publish only about gossip and net stuff and this is actually frustrating. A good site with interesting content, this is what I need. Thank you for making this website, and I will be visiting again. Do you do newsletters? I Can’t fin
ReplyDeletehttps://www.travisscottshop.net/
Thanks for writing such useful content, I like your style of writing and frequently read your content. ดาวน์โหลด spade gaming
ReplyDeleteThanks for taking the time to discuss this, I feel strongly that love and read more on this topic. If possible, such as gain knowledge, would you mind updating your blog with additional information? It is very useful for me. dreammerchofficial
ReplyDeleteI enjoyed reading your blog and it contains a lot of information. MensWalletMaker is related to fashion in which you will find beautiful and charming sleepers made by sheepskin.
ReplyDeleteNice blog and absolutely outstanding. You can do something much better but i still say this perfect.Keep trying for the best.
ReplyDeletedrewhouseofficial
Its an interesting and useful information. commedesgarconshop.net We all get highly motivation from this.
ReplyDeleteIts an interesting and useful information.
ReplyDeleteClick Here We all get highly motivation from this.
I read this article. I think You put a great deal of exertion to make this article.
ReplyDeletequackitymerch.net I like your
Thanks for sharing such beautiful information with us. We hope you will share some more information about it. We really enjoy your blog & content.charleschoice
ReplyDeleteI feel extremely cheerful to have seen your post. ranboomerchshop I found the most beautiful and fascinating one. I am really extremely glad to visit your post.
DeleteIt’s actually a nice and helpful piece of info. I’m glad that you shared this useful info with us. Please keep us up to date like this. Thanks for sharing.HatsBuddy
ReplyDeleteI enjoyed reading your blog and it contains a lot of information. Visit our store MensWalletMaker for a selection of the best wallet.
ReplyDeleteThis is a really too good post. This article gives truly quality and helpful information. I’m definitely going to look into it. Really very useful topic info is provided here. Thank you so much buddy and Keep up the good work.
ReplyDeletehttps://essentialshoodies.co.uk/
Peshawari chappal and Kaptaan Chappal are trending now a days. We deliver nation-wide. We offer different designs of Peshawari chappal to look decent and stylish, an ultimate desire! Scroll through our latest collection of peshawari chappal and order it at your finger tips.
ReplyDeleteThanks for sharing such beautiful information with us. We hope you will share some more information about louisleather. We really enjoy your blog & content.
ReplyDeleteI read this article. I think you put a great deal of exertion to make this article.Designerbeltsmaker
ReplyDeleteI'm not tired of reading at all. Everything you have written is so elaborate. I really like it. Thanks for the great article. ดาวน์โหลด bet game
ReplyDeleteI read this article. I think you put a great deal of exertion to make this article.DenimJacketsMaker
ReplyDeleteKeep up the exceptional piece of work, I read generally a couple of posts on this website page and I imagine that chromeheartsoutfit your blog is genuinely stunning and holds gatherings of amazing data.
ReplyDeletelucky me i see ghost hoodie
ReplyDeleteThanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for.RoyalRoot
ReplyDeleteThis Site give information from another people karljacobsmerch.com very well I am impress its information an information is very nice.
DeleteThis is a very nice blog and learned more knowledge to read this post thanks for sharing this informative post.silverchainmaker
ReplyDeleteThanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for mensbraceletsmaker.
ReplyDeletetheboyfriendjeans.com
ReplyDeleteVisit chrome hearts to get high quality hoodies, tees and jackets at best price and get fastest shipping services across world
ReplyDeleteshoptylerthecreator is the best thing that you should buy for your collection
ReplyDeletetyler the creator merch
https://chhoodie.com
ReplyDeletehttps://playboyhoodie.com
ReplyDeleteI feel extremely cheerful to have seen your post. I found the most beautiful and fascinating one. I am really extremely glad to visit your post.
ReplyDeletethe weeknd merch shop
Denim Jacket stylish designs and luxurious materials, denimjacketmaker is a favorite among celebrities and everyday people alike.
ReplyDeleteVery important and wonderful post here. This post is very helpful for every visitor. I hope you will soon share your next post about this discussion.logachiThanks for sharing and keep sharing
ReplyDeleteIntroduction to all (5G) Smartphone models.themobileprices.pk
ReplyDeleteIt’s actually a nice and helpful piece of info. I’m glad that you shared this useful info with us. Please keep us up to date like this. Thanks for sharing.Edcationalsolutionpk
ReplyDeleteukdenim.co.uk
ReplyDeletevloneshirts.com
ReplyDeletestreetwearbasket.com
ReplyDeleteVisit chrome hearts to get high-quality hoodies, tees, and jackets at the best price and get the fastest shipping services across the world
ReplyDeleteIts blog give information from another people very well I am impress its information an information is very nice.
ReplyDeleteEssentials Hoodies
Thanks for the information you have shared.
ReplyDeleteIf you are in search of a mens clothing store from where you can buy best printed shirts for men
trendy shirts for men,
mens co-ord sets,
shirts cut piece online.
ReplyDeleteI feel extremely cheerful to have seen your post. I found the most beautiful and fascinating one. I am really extremely glad to visit your post.
thrasherhoodies
Chrome hearts t-shirt
ReplyDeletehttps://www.chromeheartofficial.shop/
ReplyDeleteChrome Hearts Hoodies Limited Stock & all Colours of Hoodies are Available in our Chrome Hearts store. Free Shipping & Fastest delivery worldwide
Chrome Hearts Hoodies Limited Stock & all Colors of Hoodies are Available in our Chrome Hearts store. Free Shipping & Fastest delivery worldwide.
ReplyDeletechromehearthoodie
Surprise to read your article. Its very informative and interesting. Hope you will write more amazing.
ReplyDeleteDiscover the complete Chrome Hearts Sweatshirts , Sweatshirts collection on the official website Free worldwide shipping Fastest delivery.
Chrome Hearts Sweatshirts
click hereThe information given in this blog is very nice.
ReplyDeleteNikehoodie
ReplyDeletenikehoodsgreat website you have got here.
https://drakemerchshop.com/
ReplyDeleteessentialhoodies.com
ReplyDeleteClick Here
DeleteClick Here
ReplyDelete
ReplyDeleteUsually I never comment on blogs but your article is so convincing that I never stop myself to say something about it. You’re doing a great job Man,Keep it up.
Ice Cream Cone Sleeves
Thanks for sharing fmerchandise.com
ReplyDeleteThis is a very nice blog and learned more knowledge to read this post thanks for sharing this informative post.
ReplyDeletehttps://ericemanuelshop.com/eric-emanuel-shorts/
I read this article. octobersveryownshop.com I think you put a great deal of exertion to make this article.
ReplyDeleteNice post dear.
ReplyDeleteพอตบุหรี่ไฟฟ้า ราคาถูก
it's really nice and meanful. it's really cool blog. Linking is very useful thing.you have really helped lots of people who visit blog and provide them usefull informatiocharlidameliomerch.shop
ReplyDeleteVery important and wonderful post here. This post is very helpful for every visitor. I hope you will soon share your next post about this discussionshop here
ReplyDelete목포외국인출장안마
Delete여수외국인출장안마
순천외국인출장안마
나주외국인출장안마
광양외국인출장안마
포항외국인출장안마
경주외국인출장안마
Continue to send in more valuable and astonishing information on your blog so that we enjoy it.superhoodshop.com
ReplyDeleteI never stop myself to express something about your nice work. yeezygapshop You're working really hard.
ReplyDeleteLooks great article Thanks, Click here and check .
ReplyDeleteGreat stuff and important for the world.Check out for latest designs.
ReplyDeleteNot bad. Loves this thanks Puffer Jackets
ReplyDeleteHello, thank you very much for creating this blog for us to comment. เกมส์ pg slot สมัคร
ReplyDeleteExtremely helpful information particularly the last part I care for such info a lot. hokabet หวย
ReplyDeleteThe writing style which you have used in this article is very good and it made the article of better quality. สอบถาม hokabet
ReplyDeleteHi, Nice to read your article! I am looking forward to sharing your experience. Gallery dept shop
ReplyDeleteVery helpful advice on this article! It is the little changes that make the biggest changes. Thanks a lot for sharing! Asap merchandise
ReplyDeleteI am delighted to find your uploaded articles. I always find it very useful whenever someone posts interesting information or post experiences. I am thankful to have gotten these articles in my email box. Black Label Society vest
ReplyDeleteVery nice article, totally what I needed.Also visit my blog; website . 789 กีฬา
ReplyDeleteIt is really a great and useful information. And Also Visit My Site: Kashmir Tour
ReplyDelete