How to Delete data from table using php and mysql | Sanwebcorner

How to Delete data from table using php and mysql

Here is the code to display the data from the table using php and mysql. This simple code is used to delete the record you choose.You can create the database and table. Here i created database name is oops and the table name is called as a oop. And the table fields are name, lname, salary. The below code helps you to display the table information in the format of table with the delete option. When you click the delete it takes the particular id and moves to the delete.php file, In the delete.php file haves the code to delete the particular row based on the id you chosen from the table. I hope this is very useful to you and this is one of the simple concept in php.


delete-data-from-table-php-mysql



index.php

<?php
$con=mysqli_connect("localhost","root","","oops");
$sql="select * from oop";
$result=mysqli_query($con,$sql);
echo "<table><tr><th>Name</th><th>Lname</th><th>Salary</th><th>Edit</th></tr>";
while($row=mysqli_fetch_assoc($result)){

echo "<tr><td>".$row['fname']."</td>";
echo "<td>".$row['lname']."</td>";
echo "<td>".$row['salary']."</td>";
echo "<td><a href='delete.php?id=".$row['id']."'>Delete</a></td>";
}
echo "</tr></table>";
?>



delete.php

<?php
$con=mysqli_connect("localhost","root","","oops");
$id=$_GET['id'];
$query="delete  from oop where id=$id";
$sql=mysqli_query($con,$query);
header("Location: view.php");
?>

Post a Comment

Labels

360 degree view product image 3d rotate 3d text 3step-form Accordion menu ajax All Browsers Animated Background Gradient animation audio controller auto complete Best accordion menu bootstrap border bounce effect on hover Breadcrumb calculate age by dob calendar Captcha change image on mouse move color chooser countdown Counter on scroll Css css animation css buttons css hover css3 customized upload Button Date picker delete data from table Different scroll speed email otp verification email verifier Embed eventlist Expanding Menu feedbck form flash news section close button full screen menu Google custom search Google Maps Google reCAPTCHA Google site search gradient hide menu Horizontal News ticker Hover Htm Html html5 html5 form validation Iframe image hover increment decrement textbox value based on select box Javascript Jquery js Layered image effect on mouse hover marquee marquee with close button mobile number validation mobile otp login Multi-level-drop-down-menu multi-level-form mysql News ticker on hover change text to image our team page password strength checker Photoshop PHP Popup image on click the link pure css Random password Redirect page Based on the select box while submit the form responsive responsive menu responsive popup box Responsive Vertical Time line design rotate image simple coming soon page simple countdown based on end date simple typing effect slider sliding tab sms otp login statistic counter on scroll switch tag shape team member Time picker toggle toggle view transparent button underline animation up down slide validation vertical fixed sidebar Webtips Youtube