Home > Backend Development > PHP Problem > How to delete data in php

How to delete data in php

藏色散人
Release: 2023-03-13 19:18:01
Original
5011 people have browsed it

How to delete data in php: 1. Create a PHP sample file; 2. Connect to the database; 3. Delete the data with the specified id through the "delete from news where id = $id" statement.

How to delete data in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How to delete data with php?

php implements basic data addition, deletion and modification operations to delete data

Delete information based on id value delete.php

<?php
// header(&#39;Content-type:text/html;charset=utf-8&#39;);
// $conn = @mysqli_connect(&#39;localhost&#39;,&#39;root&#39;,&#39;123456&#39;,&#39;itsource&#39;);
 include(&#39;./conn.php&#39;);
 
$id = $_GET[&#39;id&#39;];
// echo $title.$autor.$source.$content;
$sql = "delete from news where id = $id";
$res  = mysqli_query($conn,$sql);
if($res)
{
echo &#39;<script>alert("删除成功");  location.href="list.php";</script>&#39;;
}else {
echo &#39;删除失败&#39;.mysql_error($conn);
}
echo &#39;<a href="list.php">返回</a>&#39;;
?>
Copy after login

Recommended learning: "PHP video tutorial

The above is the detailed content of How to delete data in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template