我试图让我的网页删除一些数据库条目,并将图片上传到ftp,并将名称设置到名为filename的数据库行中。
到目前为止,我使用复选框形式为数据库条目设置了删除功能,因此您可以一次删除多个条目,但我需要按照文件名中的图像也从ftp中删除(内容/上传)。
我正在尝试一些我在互联网上找到但却无法正常工作的东西,我删除了大部分错误,但我仍然在我的脚本中得到这些最后几个错误:
警告:mysql_fetch_array()期望参数1是资源,第10行/sites/mianautoservice.nl/www/delete_multiple.php中给出的布尔值警告:ftp_delete():content / uploads /:没有这样的文件或目录第23行/sites/mianautoservice.nl/www/delete_multiple.php无法删除内容/上传/
我认为第23行的错误是因为它在按下删除之前尝试从删除功能中获取结果,但我似乎无法弄清楚...
到目前为止,这是我的脚本:
<?php error_reporting(E_ALL); ini_set('display_errors', 1);
// Get our database connector
require("includes/conn.php");
?>
<?
if(isset($_POST['delete'])){ // Check delete button is clicked
foreach($_POST['checkbox'] as $del_id){ // loop only checked items and delete
$sql = "DELETE FROM people WHERE id='$del_id'";
$result = mysql_query($sql);
while($rows=mysql_fetch_array($result)){
}
$file = "content/uploads/" . $rows['filename'];
$ftp_server = "ftpserver";
$ftp_user_name = "username;
$ftp_user_pass = "password";
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to delete $file
if (ftp_delete($conn_id, $file)) {
echo "$file deleted successful\n";
} else {
echo "could not delete $file\n";
}
// close the connection
ftp_close($conn_id);
$result = mysql_query($sql);
}
}
// if successful redirect to delete_multiple.php
if($result){
}
?>
<?php
$sql="SELECT * FROM people ORDER BY ID";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="4" bgcolor="#FFFFFF"><strong>Selecteer welke auto('s) verkocht zijn</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>Foto</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Merkt/Type</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Beschrijving</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
echo "<div class=\"picture\">";
echo "<p>";
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td>
<td bgcolor="#FFFFFF"><? echo "<img src=\"content/uploads/" . $rows['filename'] . "\" alt=\"\" height=\"125\" width=\"200\" /><br />" . "<br />"; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['fname']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['lname']; ?></td>
</tr>
<?php
echo "</p>";
echo "</div>";
}
?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td>
</tr>
<?php
// Check if delete button active, start this
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>
<a href="indexupload.php" title="Back">Back</a>