How to delete data in php mysqli

藏色散人
Release: 2023-03-12 18:58:02
Original
2412 people have browsed it

php Mysqli method of deleting data: 1. Create a PHP sample file; 2. Connect to mysql through mysqli_connect; 3. Delete the specified data through the "delete from emp4 where id=$id" statement.

How to delete data in php mysqli

#The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.

php mysqli How to delete data?

PHP MySQLi Delete Data Record Example

The code is as follows:

<?php 
$host = &#39;localhost:3306&#39;; 
$user = &#39;root&#39;;  // MySQL用户账号
$pass = &#39;&#39;; 
$dbname = &#39;test&#39;; 
 
$conn = mysqli_connect($host, $user, $pass,$dbname); 
if(!$conn){ 
  die(&#39;Could not connect: &#39;.mysqli_connect_error()); 
} 
echo &#39;Connected successfully<br/>&#39;; 
 
$id=2; 
$sql = "delete from emp4 where id=$id"; 
if(mysqli_query($conn, $sql)){ 
 echo "Record deleted successfully"; 
}else{ 
echo "Could not deleted record: ". mysqli_error($conn); 
} 
 
mysqli_close($conn); 
?>
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to delete data in php mysqli. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!