填充更新表单的字段时,如何显示当前图像的路径,如下所示
因此,如果用户不想更改图像,则使用相同的图像。这是浏览器显示的内容:
<input type="file" value="uploads/chaps_B.jpg" name="image_edit"></input>
我有一种感觉,我photopath
不在范围内,但不确定如何修复它。所有变量都填充表单,它保存到数据库中,只是无法确定图像路径。
if(isset($_POST['update_submit']))
{
$get_products = $db->prepare("select `photopath` from `item` where
`item_id` = '$get_item' LIMIT 1");
$get_products->execute();
$path= $get_products->fetchColumn(6);
if($_FILES['image_edit']['tmp_name'] != "")
{
$edit_name = $_POST['item_name'];
$edit_description =$_POST['item_description'];
$form_id = $_POST['edit_form_id'];
$file_dir = "uploads/";
$image = $file_dir. $_FILES['image_edit']['name'];
move_uploaded_file($_FILES['image_edit']['tmp_name'], $image);
$edit_sql =$db->prepare("UPDATE item SET item_name = '$edit_name',
item_description = '$edit_description',
photopath ='$image' WHERE item_id = '$form_id'");
$edit_sql->execute();
header("Location: manage_items.php");
exit();
}
else
{
$edit_name = $_POST['item_name'];
$edit_description =$_POST['item_description'];
$form_id = $_POST['edit_form_id'];
$edit_sql =$db->prepare("UPDATE item SET item_name = '$edit_name',
item_description = '$edit_description'
WHERE item_id = '$form_id'");
$edit_sql->execute();
header("Location: manage_items.php");
exit();
}
更新表格
<form action="item_edit.php" method="post" enctype="multipart/form-data">
<input type = "text" name="item_name" value="<?php echo $item_name ?> "/>
<textarea name="item_description"><?php echo $item_description ?></textarea>
<p> <img src="<?php echo $image; ?>" width="75" height="75" /></p>
<input type="file" name="image_edit" />
<input name="edit_form_id" type="hidden" value="<?php echo $get_item ?>">
<p><input type="submit" name="update_submit" value="Update"/></p>
<p><input type="submit" name="cancel_edit" value="Cancel"/></p>
</form>
数据库结构