PHP Delete page record at the same time Refresh page deletion condition get _php skill

Source: Internet
Author: User
Function:
1, on a page to display query data, and after each data added delete function, click "Delete", delete the data, while refreshing the page
2, get the way to obtain the deletion conditions
Database connection Variable connectvars.php
Copy Code code as follows:

<?php
Server
Define (' db_host ', ' localhost ');
User name
Define (' Db_user ', ' root ');
Password
Define (' Db_password ', ' root ');
Database
Define (' db_name ', ' test ');
?>

Record Display page display.php, after each record has "delete" function, click "Delete", can delete this record, simultaneously refresh the page
Copy Code code as follows:

<?php
Require_once ' connectvars.php ';
$DBC = Mysqli_connect (db_host,db_user,db_password,db_name);
If you call this page with the ' delid ' variable in the page link, get the ' ID ' number of the record you want to delete 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 next table (if the deletion 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 record bars queried
$count = Mysqli_num_rows ($data);
?>
<title> Toyota Auto Data View </title>
<body>
<table>
<!--table column name-->
<tr>
<th> title </th>
<th> sources </th>
<th> Models </th>
<th> Main parts </th>
<th> Operations </th>
</tr>
<?php
Loop output list elements: Title, source, Cartype, Majorpart, and then add 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 to call its own page, while adding ' delid ' variables to the page link, assigning the ' ID ' number of the record in the database to get
echo ' <td><a href = '. $_server[' php_self '. Delid= '. $row [' ID ']. ' " > Delete </a></td> ';
Echo ' </tr> ';
}
?>
</table>
</body>

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.