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

//@$otp=$_POST['otp'];
//@$sssotp =$_POST['sssotp'];

     $value="SELECT * FROM paymentsetting WHERE id=1";
	 $val=mysqli_query($com,$value);
	 $row =mysqli_fetch_array($val);
	 $open_bonus=0; 
	 
//  if($otp == $sssotp)
//  {
  
    $sql4="SELECT mobile FROM loginuser WHERE mobile='$mobile'";
	 $select5=mysqli_query($com,$sql4);
		if(mysqli_num_rows($select5)=='0'){
   if($_POST['rcode']!=''){
    
     $chkrcode=mysqli_query($com,"select * from `loginuser` where `owncode`='".$rcode."'");
	$codeRow=mysqli_num_rows($chkrcode);
	if($codeRow!=''){
	 
	 $chkrcode1=mysqli_query($com,"select * from `loginuser` where `owncode`='".$rcode."'");
	 $codeRow1=mysqli_fetch_array($chkrcode1);
	 $r_id=$codeRow1['id'];
	 $reffercode=$codeRow1['code'];
	
	  $chkrcode13=mysqli_query($com,"select * from `loginuser` where `owncode`='".$reffercode."'");
	 $codeRow13=mysqli_fetch_array($chkrcode13);
	 $r_id13=$codeRow13['id'];
	
$sql= mysqli_query($com,"INSERT INTO `loginuser` (`mobile`, `password`,`show_password`,`code`,`owncode`,`privacy`,`status`) VALUES ('".$mobile."','".md5($password)."','".$password."','".$rcode."','','".$acceptTC."','1')");
$userid=mysqli_insert_id($com); 
$rand = rand(1000,10000);
$refcode=$userid.$rand;
$sql= mysqli_query($com,"UPDATE `loginuser` SET `owncode` = '$refcode' WHERE `id`= '".$userid."'");
$sql2= mysqli_query($com,"INSERT INTO `wallet`(`userid`,`amount`) VALUES ('".$userid."','$open_bonus')");
$sql3= mysqli_query($com,"INSERT INTO `bonus`(`userid`,`amount`,`level1`,`level2`) VALUES ('".$userid."','0','0','0')");
$sql6= mysqli_query($com,"INSERT INTO `interest`(`userid`,`amount`) VALUES ('".$userid."','0')");
$sql7= mysqli_query($com,"INSERT INTO `interest_1`(`userid`,`amount`) VALUES ('".$userid."','0')");
$sql8= mysqli_query($com,"INSERT INTO `interest_2`(`userid`,`amount`) VALUES ('".$userid."','0')");
$sql9= mysqli_query($com,"INSERT INTO `interest_3`(`userid`,`amount`) VALUES ('".$userid."','0')");
$sql10= mysqli_query($com,"INSERT INTO `interest_4`(`userid`,`amount`) VALUES ('".$userid."','0')");
$sql11= mysqli_query($com,"INSERT INTO `total_buy`(`userid`,`amount`) VALUES ('".$userid."','0')");
$sql12= mysqli_query($com,"INSERT INTO `total_interest`(`userid`,`amount`) VALUES ('".$userid."','0')");
$sql13= mysqli_query($com,"INSERT INTO `withdraw_balance`(`userid`,`amount`) VALUES ('".$userid."','0')");
echo "<script type='text/javascript'>alert('Register Successfuly'); window.location='login.php';</script>";

	}else{echo "<script type='text/javascript'>alert('Referal Code Not Found'); window.location='signup.php';</script>";}
	}else{
	     //print_r(123);exit;
	  $sql= mysqli_query($com,"INSERT INTO `loginuser` (`mobile`, `password`,`show_password`,`owncode`,`privacy`,`status`) VALUES ('".$mobile."','".md5($password)."','".$password."','','".$acceptTC."','1')");
$userid=mysqli_insert_id($com); 
$rand = rand(1000,10000);
$refcode=$userid.$rand;
$sql= mysqli_query($com,"UPDATE `loginuser` SET `owncode` = '$refcode' WHERE `id`= '".$userid."'");
$sql2= mysqli_query($com,"INSERT INTO `wallet`(`userid`,`amount`) VALUES ('".$userid."','$open_bonus')");
$sql3= mysqli_query($com,"INSERT INTO `bonus`(`userid`,`amount`,`level1`,`level2`) VALUES ('".$userid."','0','0','0')");
$sql6= mysqli_query($com,"INSERT INTO `interest`(`userid`,`amount`) VALUES ('".$userid."','0')");
$sql7= mysqli_query($com,"INSERT INTO `interest_1`(`userid`,`amount`) VALUES ('".$userid."','0')");
$sql8= mysqli_query($com,"INSERT INTO `interest_2`(`userid`,`amount`) VALUES ('".$userid."','0')");
$sql9= mysqli_query($com,"INSERT INTO `interest_3`(`userid`,`amount`) VALUES ('".$userid."','0')");
$sql10= mysqli_query($com,"INSERT INTO `interest_4`(`userid`,`amount`) VALUES ('".$userid."','0')");
$sql11= mysqli_query($com,"INSERT INTO `total_buy`(`userid`,`amount`) VALUES ('".$userid."','0')");
$sql12= mysqli_query($com,"INSERT INTO `total_interest`(`userid`,`amount`) VALUES ('".$userid."','0')");
$sql13= mysqli_query($com,"INSERT INTO `withdraw_balance`(`userid`,`amount`) VALUES ('".$userid."','0')");
echo "<script type='text/javascript'>alert('Register Successfuly'); window.location='login.php';</script>";
	}
	}else{
	    echo "<script type='text/javascript'>alert('applicant already applied'); window.location='signup.php';</script>";
	}
    
// }else{
// 	    echo "<script type='text/javascript'>alert('Please enter valied otp'); window.location='signup.php';</script>";
// 	}

?>