<?php
include "php_aj_3.php";<?php
$servername = "109.106.254.44";
$username = "u353443769_aras";
$password = ‘Te$t@dm1n’;
$dbname = "aleksandrs_j_php";


$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}
?>
function s($v){return htmlspecialchars($v,ENT_QUOTES,'UTF-8');}
if($_SERVER['REQUEST_METHOD']!=='POST'){header('Location: form.php');exit;}
$fullname=$_POST['fullname']??'';
$email=$_POST['email']??'';
$birthdate=$_POST['birthdate']??'';
$country=$_POST['country']??'';
$gender=$_POST['gender']??'';
$interests=$_POST['interests']??[];
$comments=$_POST['comments']??'';
$errors=[];
if(!$fullname)$errors[]="Vārds obligāts";
if(!$email||!filter_var($email,FILTER_VALIDATE_EMAIL))$errors[]="Nepareizs e-pasts";
if(!$birthdate)$errors[]="Datums obligāts";
if(!$country)$errors[]="Valsts obligāta";
if(!$gender)$errors[]="Dzimums obligāts";
?>
<!doctype html>
<html lang="lv">
<head><meta charset="utf-8"><title>Rezultāts</title></head>
<body>
<h2>Rezultāts</h2>
<?php if($errors): ?>
<ul><?php foreach($errors as $e)echo"<li>".s($e)."</li>";?></ul>
<a href="form.php">Atpakaļ</a>
<?php else: ?>
<ul>
<li>Vārds: <?=s($fullname)?></li>
<li>E-pasts: <?=s($email)?></li>
<li>Dzimšanas datums: <?=s($birthdate)?></li>
<li>Valsts: <?=s($country)?></li>
<li>Dzimums: <?=s($gender)?></li>
<li>Intereses: <?= $interests?implode(", ",array_map("s",$interests)):"Nav"?></li>
<li>Komentāri: <?=nl2br(s($comments))?></li>
</ul>
<a href="form.php">Atpakaļ</a>
<?php endif; ?>
</body>
</html>