我正在使用下面的代码来更新我的数据库中的图像和类别。代码更新类别名称,但不更新图像。它显示一个错误
未定义索引:图片在
C:\xampp\htdocs\project1\catalog\editcat.php on line 44
第 44 行是:
$img=$_FILES['picture']['name'];
PHP:
<?php
$id=$_POST['categoryid'];
$name=$_POST['categoryname'];
$img=$_FILES['picture']['name'];
$target="upload";
$qry=mysql_query("UPDATE category SET categoryname='$name' WHERE category_id=$id");
if(!$qry)
{
die("Query Failed: ". mysql_error());
}?>
<?php
if($img)
{
$image= addslashes(file_get_contents($_FILES['picture']['name']));
$image_name= addslashes($_FILES['picture']['name']);
move_uploaded_file($_FILES["picture"]["name"],$target."/" . $_FILES["picture"]["name"]);
$location=$target."/". $_FILES["picture"]["name"];
//$name=$_POST['categoryname'];
$qry=mysql_query("UPDATE category SET uploadedfile='$location' WHERE category_id=$id");
}
if(!$qry)
{
die("Query Failed: ". mysql_error());
}
?>
HTML:
<tr>
<td align="right" class="label" width="40%""><font color="blue">Category ID:</font> </td>
<td align ="left" width="60%"><input type="text" name="categoryid" id="categoryid" value="<?php echo $entries['category_id']; ?>" /></td>
</tr>
<tr>
<td align="right" class="label" width="40%""><font color="blue">Category Name:</font> </td>
<td align ="left" width="60%"><input type="text" name="categoryname" id="categoryname" value="<?php echo $entries['categoryname']; ?>" /></td>
</tr>
<tr><td align ="right" class="label" width="40%"><font color="blue">Upload File: </font></td>
<td align="left" width ="60%"> <input type="file" name="picture" ></td></tr>
<tr><td class="label" align="right"> </td><td align="left"><input type="submit" name="Submit" value="Upload" id="button1" /></td>
</tr>