<?php

include "connect.php";

$email = $_POST['email'];
$full_name = $_POST['full_name'];
$username = $_POST['username'];
$password = $_POST['password'];
$confirm = $_POST['confirm'];

if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    echo "emailerror";
    exit;
}

if(strlen($username) < 6) {
    echo "userlength";
    exit;
}

if(strlen($password) < 6) {
    echo "passlength";
    exit;
}

if($password != $confirm) {
    echo "notequal";
    exit;
}

$select = $pdo->prepare("select * from user where username = '$username'");
$select->execute();


if($select->rowCount() == 0) {
    $insert = $pdo->prepare("insert into user (email,full_name,username,password)
                                      values('$email','$full_name','$username','$password')");
    $insert->execute();

    echo "success";
} else {
    echo "repuser";
}