PHP 5 sample code for managing any database table in MySQL 5 (IV) _ PHP Tutorial

Source: Internet
Author: User
Sample code for PHP 5 to manage any database table in MySQL 5 (4 ). Continued: If you click delete to delete an entry, it will jump to del. php (as the mainstream development language) del. php (as the mainstream development language) htmlheadtitleDeletinganentryfromth continued: If you click to delete an entry, it will jump to del. php (as the mainstream development language)
// Del. php (as the mainstream development language)

Deleting an entry from the database



Delete an entry
$ Database = "sunsite ";
$ Tablename = $ _ REQUEST [tablename];
Echo "Data from $ tablename ";
MySQL (best combination with PHP) _ connect ("localhost", "root", "") or die ("Problem connecting to DataBase ");
$ Query = "show columns from $ tablename ";
$ Result = MySQL (the best combination with PHP) _ db_query ($ database, $ query );
$ Column = 0;
If ($ result)
{
Echo "Found these entries in the database:

";
Echo"







$ Query = "select * from $ tablename ";
$ Result = MySQL (the best combination with PHP) _ db_query ($ database, $ query );
If ($ result)
While ($ r = MySQL (the best combination with PHP) _ fetch_array ($ result ))
{
Echo"






";While ($ r = MySQL (the best combination with PHP) _ fetch_array ($ result )){Echo" ";$ Colname [$ column] = $ r [0];$ Column = $ column + 1;}Echo" ";MySQL (the best combination with PHP) _ free_result ($ result ); ";Echo" ";For ($ col = 1; $ col <$ column; $ col ++) echo" ";Echo" ";}Echo"
$ R [0]
(As the mainstream development language )? $ Colname [0] = $ r [0] & tablename = $ tablename "> $ r [0]$ R [$ col]
";
}
Else echo "No data .";
MySQL (the best combination with PHP) _ free_result ($ result );

?>
(As the mainstream development language )? Tablename = "> Finish


Then write the data to the database.
// Dele. php (as the mainstream development language)
$ Database = "sunsite ";
$ Tablename = $ _ GET [tablename];
MySQL (best combination with PHP) _ connect ("localhost", "root", "") or die ("Problem connecting to DataBase ");
$ Query = "show columns from $ tablename ";
$ Result = MySQL (the best combination with PHP) _ db_query ($ database, $ query );
$ Column = 0;
If ($ result)
{
While ($ r = MySQL (the best combination with PHP) _ fetch_array ($ result ))
{
$ Colname [$ column] = $ r [0];
$ Column = $ column + 1;
}
MySQL (the best combination with PHP) _ free_result ($ result );
}

$ Para = $ _ GET [$ colname [0];

MySQL (best combination with PHP) _ connect ("localhost", "root", "") or die ("Problem connecting to DataBase ");
$ Query = "delete from $ tablename where $ colname [0] = $ para ;";
$ Result = MySQL (the best combination with PHP) _ db_query ($ database, $ query );
Header ("Location: edit. php (as the mainstream development language )? Tablename = $ tablename ");
?>

The above is all the code.
Put them all under the same directory.
Note: reminder! When copying the above code, be sure to remove the tab before each line of code in the editor. otherwise, php (as the mainstream development language) 5 cannot be compiled.
In addition, $ database in each file is currently sunsite, and $ table is software, which can be modified as needed.

Comments are welcome.

Compile (as the current mainstream development language) // del. php (as the current mainstream development language) html headtitleDeleting an entry from th...

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.