The php delete page record and refresh page delete condition are obtained in GET mode
- 2020-05-12 02:19:27
- OfStack
Function:
1. Display the query data on a page and add the delete function after each data. Click "delete" to delete the data and refresh the page at the same time
2. Obtain the deletion condition with GET
Database connection variable connectvars.php
Record display page display.php. After each record, "delete" function can be used. Click "delete" to delete the record and refresh the page at the same time
1. Display the query data on a page and add the delete function after each data. Click "delete" to delete the data and refresh the page at the same time
2. Obtain the deletion condition with GET
Database connection variable connectvars.php
<?php
// The server
define('DB_HOST', 'localhost');
// The user name
define('DB_USER', 'root');
// password
define('DB_PASSWORD', 'root');
// The database
define('DB_NAME','test') ;
?>
Record display page display.php. After each record, "delete" function can be used. Click "delete" to delete the record and refresh the page at the same time
<?php
require_once 'connectvars.php';
$dbc = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
// If this page is called, the link to the page has a ' DelID' Variable, get the ' ID' Number, delete
if(isset($_GET['DelID'])){
$query = "DELETE FROM toyota WHERE ID = ".$_GET['DelID']." LIMIT 1";
mysqli_query($dbc,$query);
}
// Find all the records and display them in the following table (if the delete code above is executed, this is equivalent to refreshing the page)
$query = "SELECT * FROM toyota ORDER BY ID DESC";
$data = mysqli_query($dbc,$query);
// Count the number of records queried
$count = mysqli_num_rows($data);
?>
<html>
<head>
<title> Toyota motor data view </title>
</head>
<body>
<table>
<!-- Table column name -->
<tr>
<th> The title </th>
<th> source </th>
<th> models </th>
<th> Main components of </th>
<th> operation </th>
</tr>
<?php
// Loop output list elements: title , source , carType , majorPart, After add 1 a " delete " link
while($row = mysqli_fetch_array($data)){
echo '<tr>';
echo '<td><a href = '.$row['url'].'>'.$row['title'].'</td>';
echo '<td>'.$row['source'].'</td>';
echo '<td>'.$row['carType'].'</td>';
echo '<td>'.$row['majorPart'].'</td>';
// Click on the " delete " Link, call your own page, and add ' DelID' Variable, assigned to 'the record in the database' ID' Number for GET Way to get
echo '<td><a href = "'.$_SERVER['PHP_SELF'].'?DelID='.$row['ID'].'"> delete </a></td>';
echo '</tr>';
}
?>
</table>
</body>
</html>