<?php require_once 'sql.php'; 

$nome = sql($_POST['nome']);
if(strlen($nome) == 0){
header("Location: teste.php?error");
exit;
}
$sobrenome = sql($_POST['sobrenome']);
if(strlen($sobrenome) == 0){
header("Location: teste.php?error");
exit;
}
$email = sql($_POST['email']);
if(strlen($email) == 0){
header("Location: teste.php?error");
exit;
}
$senha = sql($_POST['password']);
if(strlen($senha) == 0){
header("Location: teste.php?error");
exit;
}
$limite_ip = sql($_POST['limite_ip']);
if(strlen($limite_ip) == 0){
header("Location: teste.php?error");
exit;
}
$level = sql($_POST['level']);
if(strlen($level) == 0){
header("Location: teste.php?error");
exit;
}
$password = hash("whirlpool",$senha);

	$query_usuario = mysql_query("SELECT * FROM `user` WHERE `email`='$email'");
	if(mysql_num_rows($query_usuario) == 1){
		header("Location: teste.php?duplicado");
		exit;
	}
		$query = mysql_query("INSERT INTO `user` (`email`, `password`, `nome`, `sobrenome`, `status`, `level`) VALUES ('$email', '$password', '$nome', '$sobrenome', '1', '$level')");
		if($query){
			$query_recu = mysql_query("SELECT * FROM `user` WHERE `email`='$email'");
			$fetch_recu = mysql_fetch_assoc($query_recu);
			$id_recu = $fetch_recu['id'];
			$query_final = mysql_query("INSERT INTO `planos` (`ip_perso`, `id_user`) VALUES ('$limite_ip', '$id_recu')");
			if($query_final){
				header("Location: teste.php?sucesso");
				exit;
			}else{
				header("Location: teste.php?error");
				exit;
			}
		}else{
			header("Location: teste.php?error");
			exit;
		}

?>