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

$name=$_POST['name'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$password=$_POST['password'];

$type=$_POST['type'];
$degree=$_POST['degree'];
$experience=$_POST['experience'];
$homevisit=$_POST['homevisit'];

$clinicvisit=$_POST['clinicvisit'];
$nightvisit=$_POST['nightcharge'];
$flatfee=$_POST['flatfee'];
$perkmrate=$_POST['perkmrate'];
$raduis=$_POST['raduis'];
$workingtime=$_POST['workingtime'];
$sundaytime=$_POST['sundaytime'];
$address=$_POST['address'];
$latitude=$_POST['latitude'];
$longitude=$_POST['longitude'];

			
          $sql ="select * from `doctors` where email='$email' ";
            $result = mysqli_query($con,$sql);
            $noofuser=0;
            while($row = mysqli_fetch_array($result)){
             $noofuser=$noofuser + 1;
			}
			
			
			
if($noofuser == 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("INSERT INTO `doctors`(`name`, `email`, `password`, `image`, `phone`, `type`, `qualification`, `experience`, `homeVisit`, `clinicVisit`, `nightCharge`, `flatFee`, `perkmrate`, `raduis`, `workingTime`, `sundaytiming`,`address`,`latitude`, `longitude`) VALUES
                                       ('$name','$email','$password','$path','$phone','$type','$degree','$experience','$homevisit','$clinicvisit','$nightvisit','$flatfee','$perkmrate','$raduis','$workingtime','$sundaytime','$address','$latitude','$longitude')");

        $sqldoctor ="select * from `doctors` where email='$email'";
            $resultdoctor = mysqli_query($con,$sqldoctor);
             
            while($rowdoctor = mysqli_fetch_array($resultdoctor)){
             $noofuserdoctor= $rowdoctor['id'];
			}
			 
if($insert > 0)
{ 
  echo $noofuserdoctor;
}
}

else if($noofuser != 0){
  echo '102';
}
else{
    echo '404';
}

?>