我是PHP的初學者,我需要做的是從我上傳的文件夾中刪除以及從phpMyAdmin刪除數據庫中的一行信息。我知道我必須實現一個取消鏈接,但我不確定如何將其放置在我的代碼中。任何幫助,將不勝感激。謝謝。如何從PHP文件夾中刪除圖像並從phpMyAdmin中刪除文件名?
$dbc = mysqli_connect('localhost', 'root', 'root', 'myimages');
$files = glob("uploads/*.*");
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
$query = "SELECT title FROM imagedata WHERE id={$_GET['id']}";
if ($r = mysqli_query($dbc, $query)) {
$row = mysqli_fetch_array($r);
print '<form action="delete_image.php" method="post">
<p style="color: red;">Are you sure you want to delete this image?</p>
<p><h4>' . $row['title'] . '</h4><br>
<input type="hidden" name="id" value="' . $_GET['id'] . '">
<input type="submit" name="submit" value="Delete this image"></p>
</form>';
} else {
print '<p style="color: red;">Could not retrieve the image because:<br>' . mysqli_error($dbc) . '.</p><p>The query being run was: ' . $query . '</p>';
}
} elseif (isset($_POST['id']) && is_numeric($_POST['id'])) {
$query = "DELETE FROM imagedata WHERE id={$_POST['id']} LIMIT 1";
$r = mysqli_query($dbc, $query);
if (mysqli_affected_rows($dbc) == 1) {
print '<p>The image has been deleted.</p>';
} else {
print '<p style="color: red;">Could not delete the image because:<br>' . mysqli_error($dbc) . '.</p><p>The query being run was: ' . $query . '</p>';
}
} else {
print '<p style="color: red;">This page has been accessed in error.</p>';
}
mysqli_close($dbc);
享受起牀,因爲你所有的SQL注入漏洞的黑客攻擊,雖然這之後。 – hanshenrik