<?php 
ob_start();
session_start();
include("include/connection.php");
////print_r($_POST);exit;
$mobile=$_POST['mobile'];
$password=$_POST['password'];
$rcode=$_POST['rcode'];
$action=$_POST['action'];


if($action=="register")
{
    $sql4="SELECT mobile FROM tbl_user WHERE mobile='$mobile'";
	 $select5=mysqli_query($con,$sql4)or die(mysqli_error($con));
		if(mysqli_num_rows($select5)=='0'){
   if($_POST['rcode']!=''){
     ///print_r(123);exit;
     $chkrcode=mysqli_query($con,"select * from `tbl_user` where `owncode`='".$rcode."'");
	$codeRow=mysqli_num_rows($chkrcode);
	if($codeRow!=''){
	 //*//
	 $chkrcode1=mysqli_query($con,"select * from `tbl_user` where `owncode`='".$rcode."'");
	 $codeRow1=mysqli_fetch_array($chkrcode1);
	 $r_id=$codeRow1['id'];
	 $reffercode=$codeRow1['code'];
	 //*///
	 
	  $chkrcode13=mysqli_query($con,"select * from `tbl_user` where `owncode`='".$reffercode."'");
	 $codeRow13=mysqli_fetch_array($chkrcode13);
	 $r_id13=$codeRow13['id'];
	

	
	
$sql= mysqli_query($con,"INSERT INTO `tbl_user` (`mobile`, `password`,`show_password`,`code`,`owncode`,`privacy`,`status`) VALUES ('".$mobile."','".md5($password)."','".$password."','".$rcode."','','".$acceptTC."','1')");
$userid=mysqli_insert_id($con);
$refcode=$userid.refcode();
$sql= mysqli_query($con,"UPDATE `tbl_user` SET `owncode` = '$refcode' WHERE `id`= '".$userid."'");
$sql2= mysqli_query($con,"INSERT INTO `tbl_wallet`(`userid`,`amount`,`envelopestatus`) VALUES ('".$userid."','0','0')");
$sql3= mysqli_query($con,"INSERT INTO `tbl_bonus`(`userid`,`amount`,`level1`,`level2`) VALUES ('".$userid."','0','0','0')");
$sql6= mysqli_query($con,"INSERT INTO `tbl_interest`(`userid`,`amount`) VALUES ('".$userid."','0')");
	if($sql){
      unset($_SESSION["signup_mobilematched"]);
      echo "<script type='text/javascript'>alert('Received Succesfully'); window.location='login';</script>";
}else{ echo"0";}
	}else{echo "<script type='text/javascript'>alert('Referal Code Not Found'); window.location='signup';</script>";}
	}else{
	  $sql= mysqli_query($con,"INSERT INTO `tbl_user` (`mobile`, `password`,`show_password`,`owncode`,`privacy`,`status`) VALUES ('".$mobile."','".md5($password)."','".$password."','','".$acceptTC."','1')");
$userid=mysqli_insert_id($con); 
$refcode=$userid.refcode();
$sql= mysqli_query($con,"UPDATE `tbl_user` SET `owncode` = '$refcode' WHERE `id`= '".$userid."'");
$sql2= mysqli_query($con,"INSERT INTO `tbl_wallet`(`userid`,`amount`,`envelopestatus`) VALUES ('".$userid."','0','0')");
$sql3= mysqli_query($con,"INSERT INTO `tbl_bonus`(`userid`,`amount`,`level1`,`level2`) VALUES ('".$userid."','0','0','0')");
$sql6= mysqli_query($con,"INSERT INTO `tbl_interest`(`userid`,`amount`) VALUES ('".$userid."','0')");
echo "<script type='text/javascript'>alert('Received Succesfully'); window.location='login';</script>";
	}
	}else{
	    echo "<script type='text/javascript'>alert('applicant already applied'); window.location='signup';</script>";
	}
    
}
else{ echo"2";}

?>