$name = trim($_POST['name']);$phone = trim($_POST['phone']);
if(isset($_POST['name']) && isset($_POST['phone'])){
$sql = mysqli_query($conn, "INSERT INTO `users` (`name`,`phone`) VALUES ('$name', '$phone')");
if($sql){ echo "data has been sent";} else{mysqli_error($conn);}
}
?>
$response = [
'res' => false,
'error' => ''
];
if ($_SERVER['REQUEST_METHOD'] === 'POST' ){
$name = trim($_POST['name']);
$phone = trim($_POST['phone']);
if($name === "" || $phone === ""){
$response['error'] = 'Заполните все поля';
}
elseif(mb_strlen($name) < 2){
$response['error'] = 'Имя не короче 2-х символов';
}
else{
$dt = date('Y-d-m H:i:s');
$mainBody = "Date: $dt\nPhone: $phone\nName: $name";
mail('vvv7220@gmail.com', 'New app in site', $mainBody);
$response['res'] = true;
}
}
echo json_encode($response);
?>