PHP Delete page record while refreshing the page delete condition obtained by Get method

Source: Internet
Author: User
Function:
1, display the query data on a page, and add the deletion function after each data, click "Delete", delete the data, and refresh the page
2. Get delete Condition by Get method
Database connection Variable connectvars.php
Copy the 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 Show page display.php, after each record has "delete" function, click "Delete", can delete the record, and refresh the page
Copy the 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 a ' 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);
}
Find 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);
Number of records queried by the statistics
$count = Mysqli_num_rows ($data);
?>
<title> Toyota car 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, followed by 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 the page itself, and add the ' delid ' variable on the page link, assign the ' ID ' number of the record in the database, for Get method
echo ' <td><a href = "'. $_server[' php_self ']. '? Delid= '. $row [' ID ']. ' " > Delete </a></td> ';
Echo ' </tr> ';
}
?>
</table>
</body>
  • Related Article

    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.