PHP 5 provides sample code for managing any database tables in MySQL 5 (3). Read the sample code for managing any database tables in MySQL 5 (3). continue: click edit to jump to edit. php // edit. phphtmlheadtitleEditinganentryfromthedatabase/titlemetahttp-equ
Continued: click edit to edit an entry and the page will jump to edit. php.
// Edit. php
Editing an entry from the database
Edit 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, select an id, and the specific content will pop out and ask the user to modify it.
// Editing. php
Editing an entry
Editing an entry
$ 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 );
}
$ Temp = $ _ GET [$ colname [0];
$ Query = "select * from $ tablename where $ colname [0] = $ temp ";
$ Result = mysql_db_query ($ database, $ query );
$ R = mysql_fetch_array ($ result );
?>
Write data to the database.
// Editdb. php
$ Database = "sunsite ";
$ Tablename = $ _ POST ['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 );
}
For ($ col = 0; $ col <$ column; $ col ++)
$ Para [$ col] =_ _ POST [$ colname [$ col];
If ($ _ POST ['name'])
{
Mysql_connect ("localhost", "root", "") or die ("Problem connecting to DataBase ");
$ Query = "update $ tablename set $ colname [1] = '$ para [1]'";
For ($ col = 2; $ col <$ column; $ col ++)
$ Query = $ query. ", $ colname [$ col] = '$ para [$ col]'";
$ Query = $ query. "where $ colname [0] = '$ para [0]';";
$ Result = mysql_db_query ($ database, $ query );
Header ("Location: edit. php? Tablename = $ tablename ");
}
Else
{
Echo "No name Entered. Please go back and reenter name ";
}
?>
To be continued.