popup not closing due to the code in parent window.

I have two php files :-

  1. editprofile.php : It shows the employee data like empname,email and profile picture. on profile picture column there is a link to change the profile picture . On click of this link pop-up opens(setprofilepic.php) and shows all the picture of an employee from which admin can select picture for employee profile.

I have written code to close the popup in setprofilepic.php after form submission and redirect it to parent window. It closes when there is a error in executing query on editprofile.php and redirects to the parent window but shows output on popup window if the code succesfully runs in editprofile.php



include (“conn.php”);

$action= $_GET[‘action’];

//echo $action;



//$profilepic = $_POST['profilepic'];
//echo "profilepic1". $profilepic;
for ($i=0;$i<count($_POST['profilepic']);$i++){
	echo "count". count($_POST['profilepic']);
		$profilepic= $_POST['profilepic'][$i];

echo "profilepicbahat". $profilepic;

$query5="update emp_photos set profile_picture=1 where image_id=$profilepic";
$query4="update emp_photos set profile_picture=0 where emp_id=$emp_id";
//"update emp_photos set profile_picture=1 where image_id=45";

echo $emp_id;
mysqli_query($conn,$query4) or die(mysqli_error());
mysqli_query($conn,$query5) or die('Error2, query failed');



<script >
function pop_up(url){

$emp_id= $_POST[‘emp_id’];


$emp_id= $_GET[‘emp_id’];

" SELECT employee.emp_id,employee.emp_name, employee.email,emp_photos.image_path
FROM employee, emp_photos
WHERE ((employee.emp_id =$emp_id) AND (emp_photos.emp_id =$emp_id AND emp_photos.profile_picture =1) )";

$rs= mysqli_query($conn,$query1);

$count =mysqli_num_rows($rs);


while($row=mysqli_fetch_array($rs ))
	<td> Employee Name :</td>
	<td> <input type= "text" name="emp_name" value=<?php echo $row['emp_name']?> /></td>
	<td> Email  :</td>
	<td> <input type= "text" name="email" value=<?php echo $row['email']?> /></td>
	<td>Image  :</td>
	<td> <img src=<?php echo $row['image_path']?> width="100" height="100" /></td>
	<td><a href="#" onclick=pop_up("setprofilepic.php?emp_id=<?php echo $row['emp_id']?>") >Change Profile Picture </a>



  1. setprofile.pic
<?php include "conn.php"; $emp_id=$_GET['emp_id']; echo $emp_id; $query="select image_id ,image_path from emp_photos where emp_id= $emp_id"; $rs=mysqli_query($conn,$query); $count= mysqli_num_rows($rs); echo $count;?> <?php while ($row = mysqli_fetch_array($rs)) {

<tr><td><img src=<?php echo $image_path ?> width="100" height="100" />
<input type="radio"  name=profilepic[] value="<?php echo $image_id ?>" /></td>
<?php } ?>

Kindly guide .

Sponsor our Newsletter | Privacy Policy | Terms of Service