I'am not able to get session variable in php i have started session in main html page. Only if part is working rest of the else part is not giving any result. it is giving me an error while reloading the page in header section
Notice: Trying to get property of non-object in C:\wamp\www\PHPMailer\extras\js\post_action.php
post_action.php
<form method='post' id='submit_form' action="process/upload_new.php?id=<?php echo $id; ?>" enctype="multipart/form-data">
<tr>
<td class="col-md-4">Upload Image</td>
<td class="col-md-8"><input name='post_image' value='<?php echo $rows["post_image"]; ?>' type="file" placeholder="Site Titlebar" class="form-control" />
<br>
<input name='submit' id='submit' type="submit" value='Upload Image' class="btn btn-success" />
</td>
</tr>
<tr>
<td>
<p> Image Preview </p>
</td>
<td>
<img src='<?php echo $rows["post_image"]; ?>' width='100px' height='100px' />
</td>
</tr>
</form>
process/upload_new.php
<?php
if($_FILES['post_image']['name'] != ''){
$uploaded_file = $_FILES['post_image']['name'];
$exp = explode(".",$uploaded_file);
$extension = end($exp);
$allowed_types = array('jpg',"jpeg","png","gif");
if(in_array($extension,$allowed_types))
{
if(is_uploaded_file($_FILES['post_image']['tmp_name'])){
$new_name = rand().".".$extension;
$path = "../images/".$new_name;
if(move_uploaded_file($_FILES['post_image']['tmp_name'],$path))
{
$_SESSION['upload_success'] = "File Uploaded succesfully";
$db_path = "images/".$new_name;
$values = ['post_image' => $db_path]; #calling update method to update image;
$id = $_GET['id'];
include_once "action_page.php";
$tablename = 'posts';
$abc = new Demo();
$res = $abc->edit($tablename,$values,$id);
unset($abc);
$_SESSION['upload_success'] = "File Uploaded succesfully";
//header("location:../post_action.php?id=$id");
}
else
{
$_SESSION['upload_error'] = "Something went wrong, file cannot be uploaded";
//header("location:../post_action.php?id=$id");
}
}
else
{
$_SESSION['upload_error'] = "Cannot upload file";
//header("location:../post_action.php?id=$id");
}
}
else{
$_SESSION['upload_warning'] = "Please upload appropriate file type";
//header("location:../post_action.php?id=$id");
}
}
else
{
$_SESSION['upload_warning'] = "Please upload file";
header("location:../post_action.php?id=$id");
}