I'm making an edit page of category list. Everything is fine but i'm not able to edit the uploaded file.
The error is:
Notice: Undefined index: fileToUpload in E:\xampp\htdocs\chandra\Categories\New cat\edit1.php on line 15
<?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
?>