gpt4 book ai didi

php删除文件夹并使用一个提交删除按钮从mysql数据库中删除一行

转载 作者:可可西里 更新时间:2023-11-01 08:50:57 25 4
gpt4 key购买 nike

    function remove_directory($directory) {
if (is_dir($directory) === true) {
$contents = scandir($directory);
unset($contents[0], $contents[1]);

foreach($contents as $object) {
$current_object = $directory.'/'.$object;
if (filetype($current_object) === 'dir') {
remove_directory($current_object);
} else {
unlink($current_object);
}
}
rmdir($directory);
}
}

function delete_row($filecode) {
$filecode = mysql_real_escape_string($filecode);

mysql_query("DELETE FROM `files` WHERE `code` = '$filecode'");

}
$query = mysql_query("SELECT `id`, `username`, `title`, LEFT(`description`, 90) as `description`, `code`, `type`, `size`, `date` FROM `files` WHERE `username` = '$userfile' ORDER BY id DESC LIMIT $start, $per_page");

while ($query_row = mysql_fetch_assoc($query)) {
$fileuser = $query_row['username'];
$filetitle = $query_row['title'];
$filecode = $query_row['code'];
$filedesc = $query_row['description'];
$filesize = $query_row['size'];
$filedate = $query_row['date'];
$filetype = $query_row['type'];

if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['dir'])) {
$dir = basename($_POST['dir']);
if ($dir[0] != '.')
remove_directory("files/$dir"); //these function work good and delete only one folder when I click Delete button
delete_row($filecode); //these function delete me all row in database in first page when I click in second page delete button too what the .... I am so angry i cant believe what is happend it's gone my database

}

if (empty($filedesc) === false) {
echo '<div id="linkstyle"><strong><a href="http://localhost/edu/1111111111111/userdownload.php?code='. $filecode . ' ">' , $filetitle , '</a></strong></div> <div id="displayfiledesc">' , $filedesc , '...</div><div id="displayfiledate"> &#149; ' , formatBytes($filesize) , ' &#149; ' , $filedate , ' &#149; ' , $filetype , '</div>';?>

<form action="" method="post">
<input type="hidden" name="dir" value="<?= $filecode?>">
<input type="submit" name="delete" id="bdelete" value="Delete"><br><br>
</form>

<?php
} else {
echo '<div id="linkstyle"> <strong><a href="http://localhost/edu/1111111111111/userdownload.php?code='. $filecode . ' ">' , $filetitle , '</a></strong></div> <div id="displayfiledate"> &#149; ' , formatBytes($filesize) , ' &#149; ' , $filedate , ' &#149; ' , $filetype , '</div>';?>

<form action="" method="post">
<input type="hidden" name="dir" value="<?= $filecode?>">
<input type="submit" name="delete" id="bdelete" value="Delete"><br><br>
</form>

我的问题太大了。当我单击删除按钮时,我预计它会从我的 mysql 数据库中删除一个文件夹和一行,但 nooooo 它会在第一页中删除一个文件夹和 mysql 数据库中的所有行,我可以看到删除按钮。我能理解的问题在哪里。有人可以帮我吗?

最佳答案

您正在从一个循环中调用 delete_row(),该循环遍历 SELECT ... FROM files WHERE username = '$userfile' 的结果集仅受限于LIMIT 子句。

虽然 remove_directory() 也在该循环中重复调用,但它总是使用相同的参数调用:'files/'.basename($_POST['dir'])

关于php删除文件夹并使用一个提交删除按钮从mysql数据库中删除一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14423466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com