#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    1
    Rep Power
    0

    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


    Code:
       <?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 
         }
      }
     	
     }
     
     2) 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;?>
      <script  type="text/javascript">
      function CloseAndRefresh() 
       {
          
     	// opener.location= "editprofile.php?action=setprofilepic& emp_id=<?php echo $emp_id ?>"; 
     	
          opener.location= "editprofile.php?action=setprofilepic&profilepic=document.getElementByName("profilepic").value& emp_id=<?php echo $emp_id ?>";
          
          self.close();
          
       }
      </script>
      <form action="editprofile.php?action=setprofilepic&emp_id=<?php echo $emp_id ?>" method="post">
      <table>
      <?php 
      while ($row = mysqli_fetch_array($rs)) {
      	
      	$image_path=$row['image_path'];
      	$image_id=$row['image_id'];?>
      	
      	<tr><td><img src=<?php echo $image_path ?> width="100" height="100" />
      	<input type="radio"  name=profilepic[] value="<?php echo $image_id ?>" /></td>
      	</tr>
      <?php }
      
      ?>
      <tr><td><input type="submit" onClick="CloseAndRefresh()" name="submit" value="Set Profile Pic" /></td></tr>
     </table></form>
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Location
    Portugal
    Posts
    24
    Rep Power
    0
    Without analyzing the code I would say that the error is in this line:

    //echo $action;
    if(isset($_GET['image_id'])){
    $image_id=$_GET['image_id'];
    }

    I think you should replace the first "image_id" for "submit" but I'm not sure, just with a brief looking at that code i think that the error is there.

IMN logo majestic logo threadwatch logo seochat tools logo