我对mysql中的数据进行了简单的编辑,一切正常,除了当我想编辑输入文件类型的图像时它不起作用,它没有给出错误消息它只是没有编辑任何东西,当我删除它工作的输入文件类型图像。通过编辑图像,我的意思是输入新图像,它将替换旧图像。
这是我的代码:
<?php
require("db.php");
$id = $_REQUEST['theId'];
$result = mysql_query("SELECT * FROM table WHERE id = '$id'");
$test = mysql_fetch_array($result);
$name = $test['Name'] ;
$email = $test['Email'] ;
$image = $test['Image'] ;
if (isset($_POST['submit']))
{
$name_save = $_POST['name'];
$email_save = $_POST['email'];
if (isset($_FILES['image']['tmp_name']))
{
$file = $_FILES['image']['tmp_name'];
$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name = addslashes($_FILES['image']['name']);
move_uploaded_file($_FILES["image"]["tmp_name"],"photos/" . $_FILES["image"]["name"]);
$image_save ="photos/" . $_FILES["image"]["name"];
mysql_query("UPDATE table SET Name ='$name_save', Email ='$email_save',Image ='$image_save' WHERE id = '$id'") or die(mysql_error());
header("Location: index.php");
}
}
?>
<form method="post">
<table>
<tr>
<td>name:</td>
<td>
<input type="text" name="name" value="<?php echo $name ?>"/>
</td>
</tr>
<tr>
<td>email</td>
<td>
<input type="text" name="email" value="<?php echo $email ?>"/>
</td>
</tr>
<tr>
<td>image</td>
<td>
<input type="file" name="image" value="<?php echo $image ?>"/>
</td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" name="submit" value="submit" />
</td>
</tr>
</table>