How can I delete the corresponding records in the database when I click a record in the table on the php webpage?

Source: Internet
Author: User
Tags form post
How can I delete the corresponding records in the database when I click a record in the table on the php webpage? For example, in a webpage written in php, tables are similar to sequence numbers & nbsp; Name & nbsp; & nbsp; Gender & nbsp; & nbs ask for advice, how can I delete the corresponding records in the database when I click a record in the table in the php webpage?
For example, the table in a webpage written in php is similar:

SN name gender deletion Edit
1. Sanman deletion and editing
2. delete and edit the female Li

The sequence number, name, and gender are read directly from the database.

How to delete the entire record with serial number 1 from the database when you click "delete" with serial number 1?
(The deletion is in href format and is linked to the processing page .)

To obtain the sequence number by clicking "delete", and then pass it to the processing page through form POST,
Operate databases on the processing page.
But I don't know how to obtain the serial number ~~~~~~~~~~
Thank you!

------ Solution ----------------------
You must use js to obtain the serial number and assign it to a field in the form for post operations.
If you delete a file, you can use Ajax to perform this operation. This prevents the entire page from being refreshed when the form is submitted.
------ Solution ----------------------
Row not found?
SN name gender deletion Edit
1. Sanman deletion and editing
2. delete and edit the female Li

How did you write these records? Let's look at the generated tokens.
------ Solution ----------------------

// Execute SQL
$ SQL = "select * from users ";
// Execute the query
$ Result = mysql_query ($ SQL );

// Result
// See mysql_result (), mysql_fetch_array (), mysql_fetch_row (), and so on.
While ($ row = mysql_fetch_assoc ($ result )){
Echo $ row ['sequence number '];
Echo $ row ['name'];
Echo $ row ['gender'];
Echo 'delete ';
}

// Release associated result set Resources
// The script is automatically executed at the end of the script.
Mysql_free_result ($ result );
?>



Replace the database field with the serial number name and gender.

------ Solution ----------------------
I wrote one just some time ago, for your reference.





































































/* Output */$ SQL = "select count (*) from blog ";$ Rs = $ con-> query ($ SQL );$ Row = $ rs-> fetch_array ();$ Num = $ row [0]; // total number of articles$ Recordnum = 8; // Number of articles displayed per page$ Pages = ceil ($ num/$ recordnum); // total number of pagesIf ($ _ GET ['id']){If ($ _ GET ['id'] = 1 ){$ Current = 1; // current page$ Pre = 1; // Previous Page$ Next = 2; // next page} Else if ($ _ GET ['id']> 1 ){$ Pre = $ _ GET ['id']-1;$ Current = $ _ GET ['id'];$ Next = $ _ GET ['id'] + 1;}} Else {// Null value$ Current = 1;$ Pre = 1;$ Next = 2;}// If any operation in SQL needs to be listed separately$ SQL = "select blog. id as blogid, blog. title, blog. content, blog. keywords, blog. listid, blog. userid, blog. ctime, blog. yes, blog. del, list. id, listtitle from blog, list where blog. del <> '1' and blog. listid = list. id order by blog. id desc limit ". ($ current-1) * $ recordnum. ", $ recordnum ";$ Rs = $ con-> query ($ SQL );While ($ row = $ rs-> fetch_assoc ()){$ Newdate = date ("Y-m-d", strtotime ($ row ['ctime']);Echo" ";}?>
Title Topic Creation time Pin to top Delete
". $ Row ['title']." ". $ Row ['listtitle']." ". $ Newdate ." Black Rain Delete

------ Solution ----------------------
"> Delete

1. remove unnecessary spaces and quotation marks from the url.
2. use $ _ GET ['id'] instead of $ _ POST ['id'].
3. if you really want to use the post method. You can use ajax

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.