<?php
include '../../conn.php';
include 'message.php'; 

$userid=$_POST['userid'];
$email=$_POST['email'];
$name=$_POST['name'];
$mycode=$_POST['mycode'];
$address=$_POST['address'];

  
 $resultdata =$con->query("select * from `users` where myCode='$mycode' and id !=$userid");
$id=0;
while($row = mysqli_fetch_array($resultdata)){
    $id=$row['id'];
      
}
if($id == 0)
{
    if($_FILES['image']['name'] != '0')  {
$valid_extensions = array('jpeg', 'jpg', 'png', 'gif', 'bmp' , 'pdf' , 'doc' , 'ppt'); // valid extensions
$path = 'images/user/'; // upload directory

$img = $_FILES['image']['name'];
$tmp = $_FILES['image']['tmp_name'];
// get uploaded file's extension
$ext = strtolower(pathinfo($img, PATHINFO_EXTENSION));
// can upload same image using rand function
$final_image = rand(1000,1000000).$img;
// check's valid format
		if(in_array($ext, $valid_extensions)) 
		{ 
		$path = $path.strtolower($final_image); 
		move_uploaded_file($tmp,'../../'.$path);
		}
$path=$baseimage.$path;
$insert = $con->query("UPDATE `users` SET `email`='$email', `name`='$name', `myCode`='$mycode', `address`='$address',`image`='$path' WHERE  id='$userid'");

        if($insert > 0)
        { 
            
         echo '101';
        // $j->status  = "101";
        // $j->message = "Success"; 
        }
        else{
            echo '104';
        // $j->status  = "104";
        // $j->message = "Email And Password wrong";
        }
}else{
    $insert = $con->query("UPDATE `users` SET `email`='$email', `name`='$name', `myCode`='$mycode', `address`='$address'  WHERE  id='$userid'");

        if($insert > 0)
        { 
          echo '101';    
         
        // $j->status  = "101";
        // $j->message = "Success"; 
        }
        else{
             echo '104';
        // $j->status  = "104";
        // $j->message = "Email And Password wrong";
        }
}

}
else{
      echo '102';
//   $j->status  = "102";
// $j->message = "This code already Used";  
}
// echo json_encode($j);         
?>