I have two php files :-
- 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
editprofile.php
[php]<?php
include (“conn.php”);
if(isset($_GET[‘action’])){
$action= $_GET[‘action’];
}
//echo $action;
if(isset($_GET[‘image_id’])){
$image_id=$_GET[‘image_id’];
}
if($action==“setprofilepic”){
$emp_id=$_GET['emp_id'];
//$profilepic = $_POST['profilepic'];
//echo "profilepic1". $profilepic;
if(isset($_POST['profilepic'])){
for ($i=0;$i<count($_POST['profilepic']);$i++){
echo "count". count($_POST['profilepic']);
//if(isset($_POST['profilepic'][$i])){
$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');
//header('location:editprofile.php?action=edit&emp_id='.$emp_id);
if($action==“edit”){
?>
<script >
function pop_up(url){
window.open(url,'win2','status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=500,height=400,directories=no,location=no')
}
</script>
<?php
if(isset($_POST['emp_id'])){
$emp_id= $_POST[‘emp_id’];
}
elseif(isset($_GET['emp_id'])){
$emp_id= $_GET[‘emp_id’];
}
$query1=
" 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);
if($count>0){
while($row=mysqli_fetch_array($rs ))
{
?>
<table>
<tr>
<td> Employee Name :</td>
<td> <input type= "text" name="emp_name" value=<?php echo $row['emp_name']?> /></td>
</tr>
<tr>
<td> Email :</td>
<td> <input type= "text" name="email" value=<?php echo $row['email']?> /></td>
</tr>
<tr>
<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>
</tr>
</table>
<?php
}
}
}
- setprofile.pic
Kindly guide .