<?php 
ob_start();
session_start();
include("include/connection.php");

@$mobile=substr($_POST['mobile'], 3);
@$email=$_POST['email'];
@$password=$_POST['password'];
@$ip=$_POST['ip'];
@$rcode=$_POST['rcode'];
@$acceptTC=$_POST['remember'];
@$action=$_POST['action'];
$otpmobile=@$_SESSION["signup_mobilematched"];

if($action=="register")
{
  if(strlen($otpmobile!==$mobile)){echo"4";}else{
	$chkuser=mysqli_query($con,"select * from `tbl_user` where `mobile`='".$mobile."'");
	$userRow=mysqli_num_rows($chkuser);
if($userRow==''){
$chkrcode=mysqli_query($con,"select * from `tbl_user` where `owncode`='".$rcode."'");
	$codeRow=mysqli_num_rows($chkrcode);
// 	if($codeRow!=''){	
$sql= mysqli_query($con,"INSERT INTO `tbl_user` (`mobile`, `ip`, `password`,`code`,`owncode`,`privacy`,`view`,`status`,`lifafa`) VALUES ('".$mobile."','".$ip."','".md5($password)."','".$rcode."','','".$acceptTC."','".$password."','1','0')");
$userid=mysqli_insert_id($con);
$refcode=refcode();
$sql= mysqli_query($con,"UPDATE `tbl_user` SET `owncode` = '$refcode' WHERE `id`= '".$userid."'");

$bonus=mysqli_query($con,"select * from `tbl_paymentsetting`");
	$bonusadd=mysqli_fetch_array($bonus);
	$refbonus = $bonusadd['bonusamount'];
	
$sql2= mysqli_query($con,"INSERT INTO `tbl_wallet`(`userid`,`amount`,`envelopestatus`) VALUES ('".$userid."','$refbonus','0')");
$sql3= mysqli_query($con,"INSERT INTO `tbl_bonus`(`userid`,`amount`,`level1`,`level2`,`level3`) VALUES ('".$userid."','0','0','0','0')");

	if($sql){
            unset($_SESSION["signup_mobilematched"]);
            echo"1";
    	    
    	}else{ 
            echo"0";   
    	}
    }else{
        echo"This Mobile Number Already has been registered, try to log-in";   
    }
}
}
?>