How to Delete Record From Table Using PHP MySQL
Allowing users to deactivate/delete their account, to delete post/article and even friend and unfriend system however require the PHP MYSQL delete query if you’re dealing with PHP MYSQL database.
To delete post, user account all require this same delete query. So in this tutorial I’ll be showing you how to delete post from table using MySQL delete query.
some useful tutorials:
Reading on I hope you already have your database, table created and some pretty records inserted in it then next is for us to get our hands dirty with the coding process.
Everything is going to be put in same web page.
So I have a DATABASE name -> delete and a TABLE name -> record.
My table has three rows: post_id, post_title and post_content.
post_id post_title post_content
1 coding coding is important
Now below is the entire code for deleting record from table:
<!DOCTYPE html>
<htmL>
<head>
<title>mysql delete query</title>
</head>
<body>
<form action="" class="signup-form-class">
<input type="submit" name="delete-submit" value="delete" />
</form>
<?php
$mydb = new mysqli("localhost", "root", "", "delete");
if(isset($_POST['delete-submit']))
{
$post_id = 1;
$postid = $post_id;
$su = $mydb->prepare("DELETE FROM record WHERE post_id='{$postid}'");
$su->execute();
If($su)
{
Echo “post deleted!”;
}
}
?>
</body>
</html>
An html form with no input field, the form has one delete button.
Read all about html form
I put both the delete button and the delete MYSQL query in the same page. As you can see, there is no METHOD attribute in the form simply because I’m not posting anything into the database.
If the delete query is successful, then you’ll get “post deleted!” report message.
Remember I did Demo about the table, which has one record, post_id =1, post_title=coding and post_content=coding is important.
I did not fetch record from the table, so I assigned the post_id value which is 1 to a variable which I name ($post_id = 1;) and assigned the variable $post_id into $postid ($postid = $post_id;).
Subscribe, follow us more are on the way.
Great blog! Your explanation style is too good, it is very impressed to me. I want more unique posts and Keeping the good work...
ReplyDeleteOracle DBA Training in Chennai
Oracle DBA Course in Chennai
Unix Training in Chennai
Oracle Training in Chennai
Pega Training in Chennai
Primavera Training in Chennai
Excel Training in Chennai
Corporate Training in Chennai
Tableau Training in Chennai
Valueable information
ReplyDeleteThanks! Please subscribe to the blog for more updates.
DeleteExcellent idea! Kind sharing this blog. I am sure that reading your blog leaves the people with some good learning experience. Great job.
ReplyDeleteIELTS Coaching in Anna Nagar
IELTS Coaching in Chennai Anna Nagar
IELTS Coaching in Adyar
IELTS Coaching in Porur
IELTS Coaching in Mumbai
Best English Speaking Classes in Mumbai
Spoken English Classes in Chennai
IELTS Coaching Centre in Chennai
ReplyDeleteThanks for sharing this great blog. That is very interesting to read and I am always searching for informative blog like this.
Html5 Training in Chennai
DOT NET Training in Chennai
Best DOT NET Training in Chennai
dot net coaching centers in chennai
best .net training institute in chennai
dot net training center in chennai
QTP Training in Chennai
LoadRunner Training in Chennai
This is great, I love it
ReplyDeleteThat's so cool
ReplyDeleteperde modelleri
ReplyDeletesms onay
mobil ödeme bozdurma
Nft Nasıl Alınır
Ankara evden eve nakliyat
Trafik Sigortası
DEDEKTOR
web sitesi kurma
AŞK KİTAPLARI
SMM PANEL
ReplyDeleteSmm Panel
iş ilanları
İNSTAGRAM TAKİPÇİ SATIN AL
hirdavatciburada.com
beyazesyateknikservisi.com.tr
servis
Tiktok para hilesi
uc satın al
ReplyDeleteözel ambulans
yurtdışı kargo
en son çıkan perde modelleri
en son çıkan perde modelleri
minecraft premium
lisans satın al
nft nasıl alınır
Good content. You write beautiful things.
ReplyDeletehacklink
vbet
sportsbet
sportsbet
taksi
hacklink
korsan taksi
mrbahis
vbet
yalova
ReplyDeleteartvin
balıkesir
tuzla
kayseri
8U5
salt likit
ReplyDeletesalt likit
0AGB1