PHP 5 provides sample code for managing any database tables in MySQL 5 (4). Read the sample code for managing any database tables in MySQL 5 (4). continue: if you click delete to delete an entry, it will jump to del. php // del. phphtmlheadtitleDeletinganentryfromthedatabase/titlemetahttp-equ
Continued: If you click delete to delete an entry, the page will jump to del. php.
// Del. php
Deleting an entry from the database
Delete an entry
$ Database = "sunsite ";
$ Tablename = $ _ REQUEST ['tablename'];
Echo "Data from $ tablename ";
Mysql_connect ("localhost", "root", "") or die ("Problem connecting to DataBase ");
$ Query = "show columns from $ tablename ";
$ Result = mysql_db_query ($ database, $ query );
$ Column = 0;
If ($ result)
{
Echo "Found these entries in the database:
";
Echo"
$ Query = "select * from $ tablename ";
$ Result = mysql_db_query ($ database, $ query );
If ($ result)
While ($ r = mysql_fetch_array ($ result ))
{
Echo"
";While ($ r = mysql_fetch_array ($ result )){Echo"
$ R [0] | ";$ Colname [$ column] = $ r [0];$ Column = $ column + 1;}Echo"
";Mysql_free_result ($ result );
";Echo"
$ R [0] | ";For ($ col = 1; $ col <$ column; $ col ++) echo"
$ R [$ col] | ";Echo"
";}Echo"
";
}
Else echo "No data .";
Mysql_free_result ($ result );
?>
"> Finish
Then write the data to the database.
// Dele. php
$ Database = "sunsite ";
$ Tablename = $ _ GET ['tablename'];
Mysql_connect ("localhost", "root", "") or die ("Problem connecting to DataBase ");
$ Query = "show columns from $ tablename ";
$ Result = mysql_db_query ($ database, $ query );
$ Column = 0;
If ($ result)
{
While ($ r = mysql_fetch_array ($ result ))
{
$ Colname [$ column] = $ r [0];
$ Column = $ column + 1;
}
Mysql_free_result ($ result );
}
$ Para = $ _ GET [$ colname [0];
Mysql_connect ("localhost", "root", "") or die ("Problem connecting to DataBase ");
$ Query = "delete from $ tablename where $ colname [0] = '$ para ';";
$ Result = mysql_db_query ($ database, $ query );
Header ("Location: edit. php? 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, php5 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.