我正在制作类别列表的编辑页面。一切都很好,但我无法编辑上传的文件。
错误是:
注意:未定义的索引:fileToUpload in 第15行的E:\ xampp \ htdocs \ chandra \ Categories \ New cat \ edit1.php
<?php
include("config.php"); //making database conn
if(isset($_GET['id'])) //if condition for getting id
{
$id=$_GET['id']; //storing result in a variable
//if we press update button - START
if(isset($_POST['update']))
{
$parent = $_POST['parent']; //getting value through post method
$child = $_POST['child'];
$status=$_POST['Status'];
$target_file = $_POST['fileToUpload'];
// update query
$query3=mysqli_query($conn,"update new_cat1 set
p_id='$parent',
name='$child' ,
Status='$status',
pic='$target_file'
where id=$id ");
// if query succes then redirect our page
if($query3)
{
$msg="Successfully Updated!!";
// header('Location:fetch.php');
echo $query3;
}
}
//IF end == if we press update button - ENDS
//select query
$query1=mysqli_query($conn,"select * from new_cat1 where id=$id");
//echo "select * from new_cat1 where id='$id'";
// while loop when query succes then store the result into variable
while($query2 = mysqli_fetch_assoc($query1)) {
$parent = $query2["p_id"];
$child = $query2["name"];
$status=$query2["Status"];
$target_file = $query2["pic"];
}
?>
<form name="update" action="" method="post" enctype="multipart/form-data">
<?php
//select query for parent category
$select_query= "Select * from new_cat1 where p_id=0";
$select_query_run = mysqli_query($conn,$select_query);
echo "<select name='parent'>";
echo "<option>---select---</option>";
while ($select_query_array= mysqli_fetch_array($select_query_run) )
{
$id = $select_query_array["id"];
$name = $select_query_array["name"]
// for showing the option statement selected
?>
<option value="<?=$id?>" <?php if($parent==$id) echo "selected='selected'"; ?> ><?=$name?></option>
<?php
}
echo "</select>";
// echo $id.$parent;
?><!-- input feild -->
<input type="text" name="child" value="<?=$child?>">
Active:<input type="radio" value="Active" name="Status" <?php if($status=="Active") echo 'checked="checked"'; ?>>
Inactive:<input type="radio" value="Inactive" name="Status" <?php if($status=="Inactive") echo 'checked="checked"'; ?>>
<input type="file" name="fileToUpload" value="<?=$target_file?>"/>
<input type="submit" value="update" name="update">
</form>
</body></html>
<?php
} // if closed
?>
答案 0 :(得分:0)
由于$_FILES
包含通过HTTP POST方法上传到当前脚本的关联项目数组。
将$_POST['fileToUpload']
更改为$_FILES['fileToUpload']
使用$_FILES['fileToUpload']['name']
将文件名存储到数据库