我在删除项目时遇到问题。我的问题是当我单击删除按钮时,该项目不会消失,但是当我刷新它时它会消失。
这是我的代码:
索引.php
<?php
$config = mysql_connect("localhost", "root", "") or die (mysql_error());
$db = mysql_select_db("darith_upload_img",$config) or die (mysql_error());
?>
<!DOCTYPE HTML>
<html>
<head></head>
<body>
<form action="upload_process.php" enctype="multipart/form-data" method="POST">
<input type="file" name="img" /><br />
<input type="submit" value="upload Now" />
</form>
<?php
$result = mysql_query("SELECT * FROM table_img");
while($row = mysql_fetch_array($result))
{
$id = $row['id_img'];
?>
<table border="1">
<tr>
<td><?php echo $row['id_img']; ?></td>
<td width="200" ><?php echo $row['location_img']; ?></td>
<td><?php echo '<img src="' . $row['location_img'] . '" width="60"/>'; ?></td>
<td><a href="index.php?id=<?php echo $id;?> " onClick="return confirm('Are you sure?')">Delete</a></td>
</tr>
</table>
<?php
}
?>
<?php
if(isset($_GET['id'])){
$id_img=$_GET['id'];
$q_del=mysql_query("DELETE FROM table_img where id_img ='$id_img'");
header("Location: http://example.com/path/to/index.php");
}
?>
</body>
</html>
上传进程.php
<?php
$config = mysql_connect("localhost", "root", "") or die (mysql_error());
$db = mysql_select_db("darith_upload_img", $config) or die (mysql_error());
if(isset($_FILES["img"]["tmp_name"]))
{
move_uploaded_file($_FILES["img"]["tmp_name"], "picture/". $_FILES["img"]["name"]);
$location = "picture/".$_FILES["img"]["name"];
$save = mysql_query("INSERT INTO table_img (location_img) VALUES ('$location')");
header("Location: http://example.com/path/to/index.php");
}
exit();
?>