Home > Backend Development > PHP Tutorial > PHP5 management code example for any Mysql5 database table (4)_PHP tutorial

PHP5 management code example for any Mysql5 database table (4)_PHP tutorial

WBOY
Release: 2016-07-13 17:32:08
Original
906 people have browsed it

Continued: If you click to delete an entry, it will jump to del.php(as the current mainstream development language)
//del.php(as the current mainstream development language) Development language)

Deleting an entry from the database



Delete an entry


< ;?
$database = "sunsite";
$tablename = $_REQUEST[tablename];
echo "

Data from $tablename

";
MySQL (The 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 "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);

$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 "

";
echo "";
for($col=1;$col<$column;$col++) echo "";
echo "";
}
echo "
$r[0]
$r[0]$r[$col]
";
}
else echo "No data.";
MySQL(The best combination with PHP)_free_result( $result);

?>
">Finish


Then write to the database
//dele.php(as now The mainstream development language)
(as the current mainstream development language)
$database = "sunsite";
$tablename = $_GET[tablename ];
MySQL(The 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(The 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 current mainstream development language)? tablename=$tablename");
?>

The above is all the code .
Just put them all in the same directory.
Attention: Reminder! When copying the above code, be sure to remove the tab in front of each line of code in the editor, otherwise php(as the current mainstream development language)5 will not compile.
And in each file, $database is currently sunsite and $table is software. This can be modified as needed.

Feedback is welcome.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508896.htmlTechArticleContinued: If you click to delete an entry, it will jump to del.php (as the current mainstream development language) //del.php (as the current mainstream development language) html headtitleDeleting an entry from th...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template