<?php
include('include/headscript.php');
$conn = new mysqli($servername, $username, $password, $database);

if ($conn->connect_error) {
    die("Errore di connessione: " . $conn->connect_error);
}

// Recupera i dati dal form
$idpages = intval($_POST['idpages']);
$namepages = $_POST['namepages'];
$slug = $_POST['slug'];
$descriptionpages = $_POST['descriptionpages'];

// Aggiorna i dati della pagina nel database
$query = $conn->prepare("UPDATE pages SET namepages = ?, slug = ?, descriptionpages = ? WHERE idpages = ?");
$query->bind_param('sssi', $namepages, $slug, $descriptionpages, $idpages);

if ($query->execute()) {
    header("Location: page-settings.php?success=1");
} else {
    header("Location: page-settings.php?error=1");
}

$query->close();
$conn->close();
