Home  >  Article  >  Backend Development  >  PHP deletes page records and refreshes the page at the same time. The deletion conditions are obtained through GET.

PHP deletes page records and refreshes the page at the same time. The deletion conditions are obtained through GET.

高洛峰
高洛峰Original
2016-12-01 09:29:05962browse

Function:
1. Display query data on a certain page, and add a delete function after each piece of data. Click "Delete" to delete the data and refresh the page at the same time
2. Use GET to obtain deletion conditions
Database connection variables connectvars.php
Copy code The code is as follows:
//Server
define('DB_HOST', 'localhost');
//Username
define('DB_USER', 'root');
// Password
define('DB_PASSWORD', 'root');
//Database
define('DB_NAME','test') ;
?>

Record display page display.php, there is "delete" after each record Function, click "Delete" to delete the record and refresh the page at the same time
Copy code The code is as follows:
require_once 'connectvars.php';
$dbc = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
//If there is a 'DelID' variable in the page link when this page is called, get the 'ID' number of the record to be deleted and delete it
if(isset($_GET['DelID'])){
$query = "DELETE FROM toyota WHERE ID = ".$_GET['DelID']." LIMIT 1";
mysqli_query($dbc,$query);
}
//Find all records and proceed in the following table Display (if the above deletion code is executed, this is equivalent to refreshing the page)
$query = "SELECT * FROM toyota ORDER BY ID DESC";
$data = mysqli_query($dbc,$query);
//Institute of Statistics Number of records queried
$count = mysqli_num_rows($data);
?>


Toyota data view


Car model
Main components
Operation

//Loop output List elements: title, source, carType, majorPart, followed by a "delete" link
while($row = mysqli_fetch_array($data)){
echo '';
echo ''.$row['title'].'';
echo ''.$row['source']. '';
echo ''.$row['carType'].'';
echo ''.$row['majorPart']. '';
//Click the "Delete" link to call your own page. At the same time, add the 'DelID' variable to the page link and assign it to the 'ID' number recorded in the database, which is used to obtain it through GET.
echo '
Delete';
echo '';
}
?>



Statement:
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