<?php
|
require '../vendor/autoload.php';
|
use Smarty\Smarty;
|
$smarty = new Smarty();
|
|
$smarty->setTemplateDir('../ihtml');
|
$smarty->setCompileDir('../compile');
|
|
$error = [];
|
$number = $_GET['number'] ?? '';
|
$email = $_GET['email'] ?? '';
|
|
|
|
function insertDataOnTable(mysqli $mysql, string $email, string $number) {
|
$query = "INSERT INTO Contact VALUES ('$email', '$number');";
|
try {
|
$mysql->query($query);
|
} catch (Exception $e) {
|
echo $e->getMessage();
|
}
|
}
|
|
if(!is_numeric($number) || strlen($number) != 10) {
|
$error['number'] = 'Numero di telefono non corretto';
|
}else {
|
$error['number'] = '';
|
}
|
|
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
$error['email'] = 'Email non valida';
|
} else {
|
$error['email'] = '';
|
}
|
|
|
|
try {
|
$conn = new mysqli('127.0.0.1', 'root', '', 'contact_db');
|
} catch (Exception $e) {
|
die($e->getMessage());
|
}
|
|
insertDataOnTable($conn, $email, $number);
|
|
|
|
|
$smarty->assign('cellNumber', $number);
|
$smarty->assign('email', $email);
|
|
$smarty->assign('error', $error);
|
|
$smarty->display('contact.tpl');
|
?>
|