Delete page records in php and refresh the page at the same time _ PHP Tutorial

Source: Internet
Author: User
Delete page records in php and refresh the page. This article introduces a simple method to refresh the current page when deleting database records. this is not implemented using ajax, but by using get to refresh the current page, this method is used in practical applications. This article introduces how to refresh the current page when deleting a database record. this method is not implemented by ajax but refreshed by get, this method has poor user experience in practical applications.

Function:

1. query data is displayed on a page, and the delete function is added after each data entry. click "delete" to delete the data and refresh the page.

2. GET deletion conditions

Database connection variable connectvars. php

The code is as follows:
// Server
Define ('Db _ host', 'localhost ');
// User name
Define ('Db _ user', 'root ');
// Password
Define ('Db _ password', 'root ');
// Database
Define ('Db _ name', 'test ');
?>

The record display page is displayed. php. each record has the "delete" function. click "delete" to delete the record and refresh the page.

The code is as follows:

Require_once 'connectvars. php ';
$ Dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME );
// If the 'delid' variable exists in the page link when this page is called, obtain 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 );
}
// Locate all records and display them in the following table (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 );
// Count the number of records queried
$ Count = mysqli_num_rows ($ data );
?>


View Toyota Motor data























// Cyclic output list elements: title, source, carType, and majorPart. a "delete" link is added.While ($ row = mysqli_fetch_array ($ data )){Echo' ';Echo' ';Echo' ';Echo' ';Echo' ';// Click the "delete" link to call its own page. at the same time, add the 'delid' variable on the page link and assign the value to the 'id' number of the record in the database for GETEcho' ';Echo' ';}?>
Title Source Vehicle model Main components Operation
'. $ Row ['title'].''. $ Row ['source'].''. $ Row ['cartype'].''. $ Row ['majorpart'].'Delete


...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.