表单以上载图像
<form method='post' action='' enctype='multipart/form-data'>
<input type='file' name='file'>
<input type='submit' value='Upload'>
</form>php编码,用于插入和显示数据库会话中的图片库以存储要删除的图像的id。
<?php
session_start();
$conn = mysqli_connect("localhost","root","","img") or die ("connection failed ");
if ($_FILES)
{
$name = $_FILES['file']['name'];
$type = $_FILES['file']['type'];
$insert = "insert into image (image) values ('".$name."')";
$sql = mysqli_query($conn,$insert);
}
$view = mysqli_query($conn,"select * from image");
while($row = mysqli_fetch_array($view))
{
extract($row);
echo "<form action=\"\" method=\"post\"><input type=\"submit\" name=\"del\" value=\"submit\"></form><a href=\"$image\"><img src=\"$image\" /></a>";
if(isset($_POST['del']))
{
$_SESSION['del_id'] = $id;
header("location:del.php");
}
}
?>del.php会话id将被删除
<?php
session_start();
$conn = mysqli_connect("localhost","root","","img") or die ("connection failed ");
$id = $_SESSION['del_id'];
$sql = mysqli_query($conn,"delete from image where id = '$id' ");
header("location:x.php");
?>发布于 2016-04-19 14:51:11
但是,我不知道从哪里获取id值来设置del_id.,您需要这样的东西:
取代:
echo "<form action=\"\" method=\"post\"><input type=\"submit\" name=\"del\" value=\"submit\"></form><a href=\"$image\"><img src=\"$image\" /></a>";在这方面:
echo "<form action=\"\" method=\"post\">";
echo "<input type=\"submit\" name=\"del\" value=\"submit\">";
echo "<input type=\"hidden\" name=\"del_id\" value=\"$row['id']\">";
echo "</form>";
echo "<a href=\"$image\"><img src=\"$image\" /></a>";并将$_SESSION['del_id'] = $id;更改为$_SESSION['del_id'] = $_POST['del_id'];
发布于 2016-04-19 14:44:51
$_SESSION['del_id'] = $id;你在哪里找到这个$id的?
https://stackoverflow.com/questions/36721549
复制相似问题