<?php
include "stuff.php";
$con = mysqli_connect($server,$user,$password,$db);
$name = $_POST['name'];

if(ctype_space($name) || strlen($name) == 0){ // if only white space or empty  
}else{
  $user_id = get_userid($con);
  $user_w_comma = ",{$user_id},";
  $table = $_POST['table'];
  if($table == "estates"){
    $type = $_POST['estateTypeList'];
    mysqli_query($con,"INSERT INTO {$table}(name,owners,type) VALUES ('{$name}','{$user_w_comma}',{$type})");
  }else if($table == "models"){
    $now = date("d/m/Y h:i:s");
    $eid = $_POST['eid'];
    mysqli_query($con,"INSERT INTO {$table}(name,estate,created,preset) VALUES ('{$name}',{$eid},'{$now}',0)");
    mysqli_query($con,"UPDATE users SET latest_estate = {$eid} WHERE id = {$user_id}");
  }
}

header("location: ../index.php");
?>
