我有两个问题:
以下是代码
if(isset($_POST['submit'])){
$target_dir = "images/staff/";
$target_dir = $target_dir . basename($_FILES["new_profilepicture"]["name"]);
$uploadOk=1;
if (file_exists($target_dir . $_FILES["new_profilepicture"]["name"])) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
if ($uploadOk==0) {
echo "Sorry, your file was not uploaded.";
}
else {
if (move_uploaded_file($_FILES["new_profilepicture"]["tmp_name"], $target_dir)) {
$imageup = $target_dir;
echo "<img src='" . $imageup . "' />";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
$_var1 = $_POST['new_name'];
$_var2 = $_POST['new_email'];
$_var3 = $_POST['new_password'];
$_var4 = $_POST['new_contactno'];
$_var5 = $_POST['new_icno'];
$_var6 = $_POST['new_address'];
$_var7 = $_POST['new_status'];
$_var8 = $imageup;
$query1 = "UPDATE staff
SET StaffName='$_var1', StaffEmail='$_var2', StaffPassword='$_var3', StaffContactNo='$_var4', StaffICNo='$_var5', StaffAddress='$_var6', StaffStatus='$_var7', StaffProfilePicture='$_var8'
WHERE StaffID='$staffID'";
$success = mysql_query($query1);//is mysql query working?
if($success){
$oldprofilepicture = $staff['StaffProfilePicture'];
if(file_exists($oldprofilepicture)){
unlink($oldprofilepicture);//delete now
}
header('location:staff_profile.php');
}
}
以下是输入新名称的行。
<tr>
<td width="170">Full Name:</td>
<td><input type="text" name="new_name" size="30" value="<?php echo $staffname ?>" /></td>
</tr>
答案 0 :(得分:0)
关于图像,创建一个隐藏的输入字段,其值与数据库中的值相同,例如:
<input type="hidden" value="/path/to/img.ext" name="old-image" />
在此之前:
if (move_uploaded_file($_FILES["new_profilepicture"]["tmp_name"], $target_dir)) {
添加:
$imageup = $_POST['old-image'];
当然,您需要对$_POST
数据进行验证。我把它从上面的例子中删除了。
这会将图像的默认值设置为已保存的版本。如果您上传新图片,那么将使用名称路径详细信息覆盖$imageup
:)
关于名称没有变化,我看不出$staffId
的值在哪里?